【问题标题】:phpcassa connection poolsphpcassa 连接池
【发布时间】:2012-04-01 13:16:54
【问题描述】:

我有一个数据访问类,它在实例化时设置三个 phpcassa 连接池,如下所示:

try { $this->cache = new ConnectionPool( BSCACHE_KEYSPACE, explode(',', BSCACHE_SERVERS), null, null, null, null, null, array( 'username' => BSCACHE_USERNAME, 'password' => BSCACHE_PASSWORD ) ); $this->indexCache = new ConnectionPool( INDEXCACHE_KEYSPACE, explode(',', INDEXCACHE_SERVERS), null, null, null, null, null, array( 'username' => INDEXCACHE_USERNAME, 'password' => INDEXCACHE_PASSWORD ) ); $this->metaCache = new ConnectionPool( METACACHE_KEYSPACE, explode(',', METACACHE_SERVERS), null, null, null, null, null, array( 'username' => METACACHE_USERNAME, 'password' => METACACHE_PASSWORD ) ); } catch (Exception $e) { return array($this->error['connection']); }

我最近在zend的php服务器上使用了代码跟踪功能对这个类进行了一点性能审计,注意到这三个连接池的设置大约需要100ms。考虑到每个连接在这个类的每个实例化中只使用一次或两次,这会浪费很多时间来设置连接。

任何人都知道任何巧妙的技巧可以让我构建这些连接池一次并让它们在类的实例之间共享?也许有一些简单的方法可以让更高级的 PHP 开发人员立即使用?

更新: 使用 APC “成功”缓存连接池,然后阅读有关持久连接的更多信息,发现 phpcassa 的 connection.php 文件(第 59 行 v 0.8.a.2)如下所示:

$socket = new TSocket($host, $port);

...好吧,TSocket 有第三个(可选)参数 $persist,默认为 false。但是当我将 phpcassa 中的第 59 行更改为将 $persist 设置为 true 时,我的回归测试对我来说简直就是地狱。他们失败的方式让我看起来像是在某个地方达到了一些“最大连接数”限制(大概是 cassandra 配置),所以我现在正在调查。

【问题讨论】:

    标签: php cassandra connection-pooling phpcassa thrift-protocol


    【解决方案1】:

    最后我没有弄乱 TSocket $persist 参数...而是编译了 phpcassa 自带的 thrift 库并启用了 apc(我没有显式缓存连接池,但是 apc 是操作码缓存,等等)。在这两个更改之间,我的三个池的连接池设置时间下降到个位数毫秒范围内......这意味着我遇到了其他瓶颈。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-20
      • 1970-01-01
      • 2015-05-02
      • 1970-01-01
      • 2012-01-15
      相关资源
      最近更新 更多