簡體   English   中英

Cassandra - DataSax PHP驅動程序 - 超時

[英]Cassandra - DataSax PHP Driver - Timeout

我使用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任何想法?

你做錯了兩件事。

  1. 允許過濾:小心。 使用allow過濾執行此查詢可能不是一個好主意,因為它可以使用大量的計算資源。 不要在生產中使用allow過濾閱讀有關使用ALLOW FILTERING的數據文檔doc 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(*)

使用withConnectTimeout (而不是或與withDefaultTimeout一起使用)可能有助於避免TimeoutException (在我的情況下確實如此)

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

但是,如果您需要這么長的超時,那么可能存在最終需要解決的潛在問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM