Request timeouts for Cassandra drivers
You can set a request timeout for each CQL statement sent by your driver.
By default, most drivers have a basic request timeout of 2 seconds.
|
To avoid excessive unnecessary timeout errors, DataStax recommends increasing the basic request timeout to 10 seconds for most applications. |
Depending on your driver, some queries might not use the basic request timeout.
For example, metadata queries like SELECT * FROM system_schema.keyspaces might use the control connection timeout.
Determine an appropriate timeout
To determine the appropriate request timeout for your driver, you must account for the time it takes for a request to be sent, executed, and returned, plus a reasonable buffer for exception handling or long-running queries.
An ideal timeout reduces unnecessary timeout errors while allowing you to detect and handle actual timeouts caused by load balancing problems, suboptimal queries, or other issues.
For example, the following factors can increase request execution time without necessarily indicating a true failure:
-
Complex or broad queries, such as large write operations, reads that return large result sets, and DDL statements
-
Retrying requests on multiple nodes if the initial attempt fails
-
Scheduling and executing speculative retries
-
Establishing new node connections if other connections have already reached the maximum number of concurrent requests
-
Repreparing CQL statements if a prepared statement ID wasn’t found on the server
-
Executing custom
RequestTrackerimplementations, if supported by the driver
Configure request timeout options
|
You might need to set different timeouts for different queries or scenarios. Execution profiles can help you manage sets of configuration options without explicitly setting them for each query. |
Timeout configuration options depend on your driver.
For example, the Java driver sets request timeouts in basic.request, and it sets other timeouts in advanced.connection.
For more information, see your driver’s documentation:
- C/C++ driver
-
See
CassStatement. - C# driver
-
See Statements.
- Go driver
- Java driver
-
See the documentation for your version of the Java driver:
- Node.js driver
-
See the documentation for your version of the Node.js driver:
- Python driver
-
You can set query timeouts in
session.execute(). For example:rows = session.execute("CREATE TABLE cycling.race_winners ( race_name text, race_position int, cyclist_name FROZEN<fullname>, PRIMARY KEY (race_name, race_position)); ", timeout=10)For more information, see the documentation for your version of the Python driver: