2016-11-21 49 views
1

我在使用Cassandra的DataSax php驅動程序超時時遇到問題。 每當我執行某個命令時,它總是拋出10S後此異常:Cassandra - DataSax PHP驅動程序 - 超時

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異常.. 我使用卡桑德拉3.6 任何想法?

回答

0

你做錯了兩件事。

  1. 允許過濾:小心。使用允許篩選執行此查詢可能不是一個好主意,因爲它可以使用大量計算資源。不要使用允許生產過濾閱讀 datastax文檔有關使用允許過濾的 https://docs.datastax.com/en/cql/3.3/cql/cql_reference/select_r.html?hl=allow,filter
  2. 計數():這也是一個可怕的想法使用計數()。計數()實際上遍歷所有數據。因此,來自userdetails且沒有限制的select count()預計會在該行數超時。一些細節在這裏:http://planetcassandra.org/blog/counting-key-in-cassandra/

如何解決它?

  • 而不是使用允許過濾的,你應該,如果你需要查詢,而不分區鍵創建 您的集羣列的索引表。
  • 而不是使用計數(*)你應該創建一個櫃檯表
相關問題