Cassandra Read Performance Tuning on 5.0: What the Knobs Do

Updated

Apache Cassandra logo

The first thing to check is not a cache setting, it is whether your query names a partition key — a filtering read on the same table scanned 21,500 rows to return 5 in a traced test. After that, these are the knobs that exist on 5.0, and the shipped defaults for a new table are:

    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND compression = {'chunk_length_in_kb': '16', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND read_repair = 'BLOCKING'
    AND speculative_retry = '99p'

Every default there is already the right answer for most tables. The rest of this page is about what each one does and how to see it working.

Bloom filters skip an index lookup, not a disk read

Two identical tables, five overlapping SSTables each, autocompaction disabled. One has the default bloom_filter_fp_chance = 0.01; the other has it set to 1.0, which switches the filter off. Reading a key that exists in neither, with tracing on:

-- bloom_filter_fp_chance = 0.01
 Bloom filter allows skipping sstable 5
 Bloom filter allows skipping sstable 4
 Bloom filter allows skipping sstable 3
 Bloom filter allows skipping sstable 2
 Bloom filter allows skipping sstable 1
 Read 0 live rows and 0 tombstone cells

-- bloom_filter_fp_chance = 1.0
 Partition index lookup allows skipping sstable 5
 Partition index lookup allows skipping sstable 4
 Partition index lookup allows skipping sstable 3
 Partition index lookup allows skipping sstable 2
 Partition index lookup allows skipping sstable 1
 Read 0 live rows and 0 tombstone cells

Both reads correctly touch no row data. The difference is which structure did the excluding: an in-memory filter, or a per-SSTable partition index. That is the honest description of what a bloom filter buys — it removes an index lookup per SSTable per read — and it explains why tuning it matters most for tables with many SSTables per read (STCS) and least for tables with few (LCS, which is why Cassandra defaults LCS tables to the looser bloom_filter_fp_chance = 0.1) — so the compaction strategy the table runs decides how much this knob is worth before you touch it.

The cost is memory, and it is reported per table:

Bloom filter space used: on=12560 off=0

The useful signal is not the filter’s size, it is its miss rate. nodetool tablestats prints Bloom filter false positives and Bloom filter false ratio; a false ratio climbing well above your configured bloom_filter_fp_chance is the only evidence that lowering it would help.

What nodetool tablestats reports — and what it does not

This is the actual output, unedited, for a table that has been written to 8,000 times and never read:

Keyspace: hw_c1
	Read Count: 0
	Read Latency: NaN ms
	Write Count: 8000
	Write Latency: 0.00540825 ms
		Table: lcs_demo
		SSTable count: 1
		Max SSTable size: 127.954KiB
		SSTables in each level: [1, 0, 0, 0, 0, 0, 0, 0, 0]
		Space used (live): 131025
		SSTable Compression Ratio: 0.15080
		Number of partitions (estimate): 4000
		Local read count: 0
		Local read latency: NaN ms
		Local write count: 4000
		Bloom filter false positives: 0
		Bloom filter false ratio: 0.00000
		Bloom filter space used: 2512
		Index summary off heap memory used: 512

(The two millisecond figures there come from one node on a laptop and are not a benchmark; they are shown because the shape of the output is the point.) The same restraint applies to how-to-optimize-read-performance.sh: it asserts output shapes and the shipped defaults, never a latency or throughput number, against a one-node Cassandra 5.x that it starts on ports 9155, 7116 and 7313, so an installed node is left alone.

Two traps. Local read latency is the node’s own histogram, not the client’s — it excludes coordination, and it reads NaN ms until reads actually happen, exactly as above. And tablestats contains no cache hit rate at all. Caches are node-wide, so they live in nodetool info:

Key Cache     : entries 38, size 7.05 KiB, capacity 100 MiB, 170 hits, 199 requests, 0.854 recent hit rate, 14400 save period in seconds
Row Cache     : entries 0, size 0 bytes, capacity 0 bytes, 0 hits, 0 requests, NaN recent hit rate, 0 save period in seconds
Counter Cache : entries 0, size 0 bytes, capacity 50 MiB, 0 hits, 0 requests, NaN recent hit rate, 7200 save period in seconds

The row cache has capacity 0 bytes. It is off, on a stock 5.0.9 node, and the running node’s own configuration dump confirms it with row_cache_size=0MiB. Any advice to “use the row cache” is advice to turn something on first — and it is usually the wrong thing to turn on, because it caches the head of a partition and is invalidated by any write to that partition. The key cache, which is on by default at 100 MiB, is the one already earning its keep. When the row cache is enabled it uses the off-heap OHCProvider.

Read repair is already on, and its old dials are gone

read_repair = 'BLOCKING' is the table default — the Cassandra read repair documentation lists the option’s values as blocking (default) and none: when a read at a consistency level above ONE finds replicas disagreeing, the coordinator writes the newer value back and blocks until that write is acknowledged. There is nothing to enable. The settings that used to make this probabilistic no longer exist:

cqlsh> ALTER TABLE hw_v4.t WITH read_repair_chance = 0.1;
SyntaxException: Unknown property 'read_repair_chance'

cqlsh> ALTER TABLE hw_v4.t WITH dclocal_read_repair_chance = 0.1;
SyntaxException: Unknown property 'dclocal_read_repair_chance'

If you find those in a tutorial or an old schema file, it predates Cassandra 4.0.

Consistency level is a latency knob with a hard floor

Lowering the consistency level lowers how many replicas the coordinator waits for, and that is real. But the level is bounded by the replication factor, and asking for more than exists fails immediately rather than degrading:

cqlsh> CONSISTENCY TWO; SELECT * FROM hw_v4.t WHERE id=5;
Unavailable('Error from server: code=1000 [Unavailable exception] message="Cannot achieve consistency
level TWO" info={\'consistency\': \'TWO\', \'required_replicas\': 2, \'alive_replicas\': 1}')

Note the corollary: at RF=1, QUORUM succeeds and is identical to ONE. A consistency level only means something relative to the keyspace’s replication factor, so “use QUORUM for safety” is meaningless without stating RF. On multi-datacentre keyspaces, LOCAL_QUORUM is the one that avoids cross-region round trips — QUORUM there can require replicas on another continent.

Compression, briefly

New tables get LZ4 with a 16 KiB chunk length; the change from 64 KiB landed in CASSANDRA-13241 and is in the shipped CHANGES.txt. Chunk length is a read-amplification setting: a read of one row decompresses a whole chunk, so smaller chunks mean less wasted I/O per read and a slightly worse compression ratio. Lower it toward 4 KiB for small-row, random-read tables; raise it for analytic scans. Changing the compressor to Snappy or Deflate is almost never the win — LZ4 is chosen for decompression speed on the read path.

The order to try things in

Fix the data model first: a query that names a partition key, and partitions that do not grow without bound. Then look at SSTables per read via a trace and nodetool tablehistograms, because that number multiplies everything else. Then set consistency level to the weakest one your correctness argument allows. Cache tuning comes last and mostly means leaving the row cache off. If you want a real measurement rather than a guess, cassandra-stress ships in the same bin/ directory as nodetool — and it must run against hardware resembling production, which is exactly why no number from this article’s test node appears above.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.