giordanolima
giordanolima

Reputation: 1218

Cassandra - DataSax PHP Driver - Timeout

I'm having problems with timeout using the DataSax php driver for Cassandra. Whenever I execute a certain command it always throws this exception after 10s:

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

My php code is like this:

$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();

My settings in cassandra.yaml is:

# 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

I've already tried this:

$result    = $session->execute($statement,new Cassandra\ExecutionOptions([
        'timeout' => 120
    ])
);

and this:

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

and this:

set_time_limit(0)

And it always throws the TimeoutException after 10s.. I'm using Cassandra 3.6 Any idea?

Upvotes: 3

Views: 1141

Answers (2)

towr
towr

Reputation: 4167

Using withConnectTimeout (instead of, or together with withDefaultTimeout) might help avoid a TimeoutException (it did in my case)

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

However, if you need such a long timeout, then there is probably an underlying problem that will need solving eventually.

Upvotes: 1

Ashraful Islam
Ashraful Islam

Reputation: 12840

Two things you are doing wrong.

  1. ALLOW FILTERING : Be careful. Executing this query with allow filtering might not be a good idea as it can use a lot of your computing resources. Don't use allow filtering in production Read the datastax doc about using ALLOW FILTERING https://docs.datastax.com/en/cql/3.3/cql/cql_reference/select_r.html?hl=allow,filter
  2. count() : It also a terrible idea to use count(). count() actually pages through all the data. So a select count() from userdetails without a limit would be expected to timeout with that many rows. Some details here: http://planetcassandra.org/blog/counting-key-in-cassandra/

How to Fix it ?

  • Instead of using ALLOW FILTERING, You should create index table of your clustering column if you need query without partition key.
  • Instead of using count(*) you should create a counter table

Upvotes: 0

Related Questions