【问题标题】:Cassandra - DataSax PHP Driver - TimeoutCassandra - DataSax PHP 驱动程序 - 超时
【发布时间】:2017-04-05 05:47:31
【问题描述】:

我在使用 Cassandra 的 DataSax php 驱动程序时遇到超时问题。 每当我执行某个命令时,它总是在 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 有什么想法吗?

【问题讨论】:

  • 您找到解决方案了吗?我有同样的问题 - 无论我改变什么,都会在 10 秒后超时。

标签: php cassandra


【解决方案1】:

使用withConnectTimeout(代替withDefaultTimeout 或与withDefaultTimeout 一起使用)可能有助于避免TimeoutException(在我的情况下确实如此)

$cluster = Cassandra::cluster()->withConnectTimeout(60)->build();

但是,如果您需要这么长的超时时间,那么可能存在最终需要解决的潜在问题。

【讨论】:

    【解决方案2】:

    你做错了两件事。

    1. 允许过滤:小心。使用允许过滤执行此查询可能不是一个好主意,因为它会占用大量计算资源。不要在生产中使用允许过滤阅读 关于使用 ALLOW FILTERING 的 datastax 文档 https://docs.datastax.com/en/cql/3.3/cql/cql_reference/select_r.html?hl=allow,filter
    2. count() :使用 count() 也是一个糟糕的主意。 count() 实际上对所有数据进行分页。因此,没有限制的 userdetails 中的 select count() 预计会因那么多行而超时。这里有一些细节:http://planetcassandra.org/blog/counting-key-in-cassandra/

    如何解决?

    • 您应该创建索引表,而不是使用 ALLOW FILTERING 如果您需要不带分区键的查询,请使用您的集群列。
    • 您应该创建一个计数器表,而不是使用 count(*)

    【讨论】:

      猜你喜欢
      • 2016-02-27
      • 2015-11-16
      • 1970-01-01
      • 2018-11-05
      • 2020-07-18
      • 2016-09-21
      • 2014-03-16
      • 2018-07-17
      • 2016-05-18
      相关资源
      最近更新 更多