Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

arsen.gasparyan.05_188257 avatar image
arsen.gasparyan.05_188257 asked ·

Why is my aggregated query returning "DriverTimeoutException: Query timed out after PT2S"?

This is my query!

ResultSet rs = session.execute("SELECT min(value) AS count, timestamp  FROM iot.test WHERE bucked_id=101010 AND sensor_id=123456 AND metric_id='123456' AND timestamp>=1596251515073 AND timestamp<1598851515073 GROUP BY floor(timestamp,10m)");

I received following error

Exception in thread "main" com.datastax.oss.driver.api.core.DriverTimeoutException: Query timed out after PT2S
        at com.datastax.oss.driver.api.core.DriverTimeoutException.copy(DriverTimeoutException.java:34)
        at com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures.getUninterruptibly(CompletableFutures.java:149)
        at com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor.process(CqlRequestSyncProcessor.java:53)
        at com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor.process(CqlRequestSyncProcessor.java:30)
        at com.datastax.oss.driver.internal.core.session.DefaultSession.execute(DefaultSession.java:230)
        at com.datastax.oss.driver.api.core.cql.SyncCqlSession.execute(SyncCqlSession.java:53)
        at com.datastax.oss.driver.api.core.cql.SyncCqlSession.execute(SyncCqlSession.java:73)
        at Mian.main(Mian.java:38)

But via cqlsh it is normal.

driverjava
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

@arsen.gasparyan.05_188257 The error you posted indicates that the driver gave up waiting for the coordinator to respond:

Exception in thread "main" com.datastax.oss.driver.api.core.DriverTimeoutException: Query timed out after PT2S

PT2S is a duration of 2 seconds expressed in ISO 8601 format. The driver timeout exception is thrown when the driver-side basic.request.timeout is less than the server-side timeout. The default request timeouts in cassandra.yaml are:

read_request_timeout_in_ms: 5000
range_request_timeout_in_ms: 10000
aggregated_request_timeout_in_ms: 120000
write_request_timeout_in_ms: 2000
counter_write_request_timeout_in_ms: 5000
truncate_request_timeout_in_ms: 60000
request_timeout_in_ms: 10000

In your case where you're doing an expensive aggregated read request with the MIN() function, I would suggest setting up an execution profile to deal with long aggregated requests. For example:

datastax-java-driver {
  profiles {
    ...
    aggregatedprofile {
      basic.request.timeout = 12 seconds
      basic.request.consistency = LOCAL_QUORUM
    }
}

You would then set the profile when you execute a statement with the setExecutionProfileName() method. For example:

SimpleStatement s =
  SimpleStatement.builder("SELECT min(value) AS count, timestamp  FROM iot.test WHERE bucked_id=101010 AND sensor_id=123456 AND metric_id='123456' AND timestamp>=1596251515073 AND timestamp<1598851515073 GROUP BY floor(timestamp,10m)")
      .setExecutionProfileName("aggregatedprofile")
      .build();
ResultSet rs = session.execute(s);

For more info on execution profiles, see the Java core driver configuration page. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.