Cassandra - DataStax PHP驱动程序 - 超时

3

我在使用DataStax php驱动程序连接Cassandra时遇到了超时问题。每当我执行某个命令时,它总是在10秒后抛出异常:

PHP Fatal error:  Uncaught exception 'Cassandra\Exception\TimeoutException' with message 'Request timed out'

我的php代码如下:

$cluster   = Cassandra::cluster()->build();
$session   = $cluster->connect("my_base");
$statement = new Cassandra\SimpleStatement("SELECT COUNT(*) as c FROM my_table WHERE my_colunm = 1 AND my_colunm2 >= '2015-01-01' ALLOW FILTERING")
$result    = $session->execute($statement);
$row = $result->first();

我的cassandra.yaml文件中的设置如下:

# How long the coordinator should wait for read operations to complete
read_request_timeout_in_ms: 500000
# How long the coordinator should wait for seq or index scans to complete
range_request_timeout_in_ms: 1000000
# How long the coordinator should wait for writes to complete
write_request_timeout_in_ms: 2000
# How long the coordinator should wait for counter writes to complete
counter_write_request_timeout_in_ms: 50000
# How long a coordinator should continue to retry a CAS operation
# that contends with other proposals for the same row
cas_contention_timeout_in_ms: 50000
# How long the coordinator should wait for truncates to complete
# (This can be much longer, because unless auto_snapshot is disabled
# we need to flush first so we can snapshot before removing the data.)
truncate_request_timeout_in_ms: 60000
# The default timeout for other, miscellaneous operations
request_timeout_in_ms: 1000000

我已经尝试过这个方法:
$result    = $session->execute($statement,new Cassandra\ExecutionOptions([
        'timeout' => 120
    ])
);

并且还有这个:

$cluster   = Cassandra::cluster()->withDefaultTimeout(120)->build();

还有这个:

set_time_limit(0)

无论如何,它总是在10秒后抛出TimeoutException。
我使用的是Cassandra 3.6,有任何想法吗?


1
你找到解决方案了吗?我也遇到了同样的问题——无论我改变什么,都会在10秒后超时。 - alienn
2个回答

1
使用withConnectTimeout(而不是或与withDefaultTimeout一起)可能有助于避免TimeoutException(在我的情况下确实如此)。
$cluster = Cassandra::cluster()->withConnectTimeout(60)->build();

然而,如果您需要如此长的超时时间,那么很可能存在一个潜在的问题,最终需要解决。

0

你正在做两件错误的事情。

  1. ALLOW FILTERING:小心。使用allow filtering执行此查询可能不是一个好主意,因为它可能会使用大量的计算资源。在生产环境中不要使用allow filtering,请阅读datastax文档了解如何使用ALLOW FILTERING https://docs.datastax.com/en/cql/3.3/cql/cql_reference/select_r.html?hl=allow,filter
  2. count():使用count()也是一个可怕的想法。count()实际上遍历所有数据。因此,从userdetails选择count()而没有限制将预计超时那么多行。这里有一些细节:http://planetcassandra.org/blog/counting-key-in-cassandra/

如何修复?

  • 如果您需要在没有分区键的情况下进行查询,建议您创建聚簇列的索引表,而不是使用ALLOW FILTERING。
  • 如果您需要计算行数,建议您创建一个计数器表,而不是使用count(*)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接