Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
phpcassa连接池_Php_Cassandra_Connection Pooling_Phpcassa_Thrift Protocol - Fatal编程技术网

phpcassa连接池

phpcassa连接池,php,cassandra,connection-pooling,phpcassa,thrift-protocol,Php,Cassandra,Connection Pooling,Phpcassa,Thrift Protocol,我有一个数据访问类,它在实例化时设置了三个phpcassa连接池,如下所示: try { $this->cache = new ConnectionPool( BSCACHE_KEYSPACE, explode(',', BSCACHE_SERVERS), null, null, null, null, null, array( 'username' => BSCACHE_USERNAME, 'password' => BSCACHE

我有一个数据访问类,它在实例化时设置了三个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']);
}

$socket = new TSocket($host, $port);
我最近使用zend的php服务器上的代码跟踪功能对这个类进行了一些性能审计,并注意到这三个连接池的设置耗时约100毫秒。考虑到每个类的每个实例化只使用一次或两次连接,连接设置会浪费很多时间

有人知道有什么聪明的技巧可以让我一次性构建这些连接池,并在类的实例化之间共享它们吗?也许有一种简单的方法可以让更高级的PHP开发人员立即做到这一点

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


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']);
}

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

。。。TSocket还有第三个(可选)参数$persist,默认为false。但当我将phpcassa中的第59行更改为将$persist设置为true时,我的回归测试就完蛋了。他们失败的方式让我看起来好像在某处达到了一些“最大连接数”限制(可能是cassandra配置),所以我现在正在研究这个问题。

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