Cassandra ReadTimeoutException
ReadTimeoutException occurs when a read operation cannot complete within the configured timeout period.
Error Message
Section titled “Error Message”com.datastax.driver.core.exceptions.ReadTimeoutException: Cassandra timeout during read queryat consistency LOCAL_QUORUM (2 responses were required but only 1 replica responded)Or in logs:
ERROR [ReadStage-2] ReadCallback.java:123 - Read timeout: 5000 msSymptoms
Section titled “Symptoms”- Client receives
ReadTimeoutException - High read latencies in
nodetool proxyhistograms - Increased
ReadTimeoutcount in JMX metrics - Slow or unresponsive queries
Diagnosis
Section titled “Diagnosis”Step 1: Check Read Latency
Section titled “Step 1: Check Read Latency”# Overall read latenciesnodetool proxyhistograms
# Per-table latenciesnodetool tablehistograms my_keyspace my_tableWhat to look for: p99 latencies > timeout value (default 5000ms)
Step 2: Check Table Statistics
Section titled “Step 2: Check Table Statistics”nodetool tablestats my_keyspace.my_tableKey metrics:
| Metric | Warning Level | Indicates |
|---|---|---|
| SSTable count | > 20 | Compaction lag |
| Partition size (max) | > 100MB | Large partitions |
| Tombstone scans | > 1000 | Too many tombstones |
| Bloom filter false positive ratio | > 0.01 | Inefficient bloom filters |
Step 3: Check for Tombstones
Section titled “Step 3: Check for Tombstones”# Enable query tracingcqlsh> TRACING ON;cqlsh> SELECT * FROM my_table WHERE pk = 'value';Look for: “Scanned X tombstones” messages.
Step 4: Check Thread Pool Status
Section titled “Step 4: Check Thread Pool Status”nodetool tpstatsWarning signs:
ReadStagepending > 0 across successive runs, rather than in a single sample. A queue that clears between runs is a burst; one that holds means the pool is not keeping up- Dropped
READmessages in the second section of the output, which count reads discarded after waiting pastread_request_timeout. A dropped read is not retried by the node, so it becomes the client-visible timeout - The same two readings on the other replicas for the affected partition, which separates one slow node from a cluster-wide limit
The Blocked and All time blocked columns stay at zero on ReadStage on 5.0, 4.1 and 4.0 whatever the load, so neither is usable here; What the blocked counters report covers why. For the work ReadStage performs and the definition of each counter above, see Thread Pools.
Step 5: Check Disk I/O
Section titled “Step 5: Check Disk I/O”iostat -x 1 5Warning signs:
%util> 80%await> 10ms- High
r_await(read wait time)
Step 6: Check Garbage Collection
Section titled “Step 6: Check Garbage Collection”grep "GC pause" /var/log/cassandra/gc.log | tail -20Warning signs:
- GC pauses > 500ms
- Frequent full GC
Root Causes
Section titled “Root Causes”1. Large Partitions
Section titled “1. Large Partitions”Symptoms: Single partition queries slow, multi-partition queries fast.
Verify:
nodetool tablestats my_keyspace.my_table | grep -i partitionSolution:
- Redesign data model to use smaller partitions
- Use bucketing (e.g., by time period)
- Set partition size alerts
2. Too Many Tombstones
Section titled “2. Too Many Tombstones”Symptoms: Queries become slower after deletes, slow range queries.
Verify:
# Run with tracingTRACING ON;SELECT * FROM my_table WHERE partition_key = 'x';# Look for "Scanned X tombstones"Solution:
- Reduce
gc_grace_seconds(after ensuring repair runs regularly) - Avoid deletes if possible (use TTL instead)
- Run compaction to purge tombstones
nodetool compact my_keyspace my_table3. High SSTable Count
Section titled “3. High SSTable Count”Symptoms: Read latency increases over time, compaction pending.
Verify:
nodetool compactionstatsnodetool tablestats my_keyspace.my_table | grep "SSTable count"Solution:
- Increase compaction throughput
nodetool setcompactionthroughput 128- Force compaction
nodetool compact my_keyspace my_table4. Slow Disk I/O
Section titled “4. Slow Disk I/O”Symptoms: All operations slow, high disk utilization.
Verify:
iostat -x 1 10Solution:
- Use SSDs (required for production)
- Check for disk issues
- Reduce concurrent operations
5. Network Issues
Section titled “5. Network Issues”Symptoms: Only some nodes show timeouts, inter-node latency high.
Verify:
# Check cross-node latencynodetool netstats
# Ping testping -c 10 <other-node-ip>Solution:
- Check network infrastructure
- Verify firewall rules
- Check for packet loss
6. GC Pressure
Section titled “6. GC Pressure”Symptoms: Intermittent timeouts, correlated with GC pauses.
Verify:
grep -E "GC|pause" /var/log/cassandra/gc.log | tail -50Solution:
- Confirm the heap and collector match what the release computes and ships, rather than a value set by hand (heap sizing per version)
- Work through GC Pause Issues, which separates a pause caused by the collector configuration from one caused by what the heap retains
- Check for unbounded growth in what the heap holds, which High Memory Usage covers
7. Overloaded Cluster
Section titled “7. Overloaded Cluster”Symptoms: All operations slow, high thread pool utilization.
Verify:
nodetool tpstatsSolution:
- Add nodes
- Reduce traffic
- Optimize queries
Resolution
Section titled “Resolution”Immediate Actions
Section titled “Immediate Actions”-
Increase timeout (temporary fix):
cassandra.yaml read_request_timeout_in_ms: 10000 -
Reduce consistency level (if acceptable):
CONSISTENCY LOCAL_ONE;SELECT * FROM my_table WHERE pk = 'x'; -
Force compaction (if SSTable count high):
Terminal window nodetool compact my_keyspace my_table
Long-term Fixes
Section titled “Long-term Fixes”-
Fix data model:
- Smaller partitions (< 100MB)
- Avoid unbounded partition growth
- Use appropriate clustering columns
-
Tune compaction:
# For time-series datacompaction = {'class': 'TimeWindowCompactionStrategy','compaction_window_unit': 'HOURS','compaction_window_size': '1'} -
Add capacity:
- Add nodes if cluster is overloaded
- Scale horizontally
-
Optimize queries:
- Add appropriate indexes
- Use LIMIT clause
- Avoid full table scans
Prevention
Section titled “Prevention”Monitoring
Section titled “Monitoring”Set up alerts for:
| Metric | Warning | Critical |
|---|---|---|
| Read latency p99 | > 50ms | > 500ms |
| SSTable count | > 20 | > 50 |
| ReadStage pending | > 0 (sustained) | > 10 |
| GC pause time | > 200ms | > 500ms |
Best Practices
Section titled “Best Practices”- Design for your queries: Model data based on access patterns
- Keep partitions small: Target < 100MB per partition
- Avoid tombstones: Use TTL instead of DELETE when possible
- Monitor proactively: Track read latencies over time
- Run repairs: Keep data consistent across replicas