Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

Operating System Tuning for Cassandra

Optimize your Linux operating system for Cassandra performance.

Terminal window
# Check current scheduler
cat /sys/block/sda/queue/scheduler
# Set to mq-deadline or none for SSDs. These are the blk-mq scheduler names on
# current kernels (RHEL/Rocky 8+, Ubuntu 20.04+); the legacy single-queue names
# "deadline" and "noop" no longer exist there and writing them fails.
echo mq-deadline > /sys/block/sda/queue/scheduler
# Or for NVMe
echo none > /sys/block/nvme0n1/queue/scheduler

Point reads by partition key reach SSTables as small random I/O, so read-ahead beyond the data actually requested tends to waste I/O bandwidth and fill the page cache with data that may never be used. Sequential operations such as range scans, compaction, and streaming do benefit from read-ahead, so the value is a trade-off between the two access patterns. A low 8 KiB value suits SSDs and NVMe devices, where seeks are cheap; on HDDs seeks are expensive, so a larger 64 KiB value reads more data per seek.

blockdev expresses read-ahead in 512-byte sectors, so the sector count is twice the size in KiB: 16 sectors is 8 KiB, and 128 sectors is 64 KiB.

Terminal window
# Set read-ahead in 512-byte sectors: 16 = 8 KiB (SSD), 128 = 64 KiB (HDD)
blockdev --setra 16 /dev/sda
# Verify (reports sectors, so 16 confirms 8 KiB)
blockdev --getra /dev/sda

Values set with blockdev do not survive a reboot; a udev rule makes them persistent. The sysfs attribute queue/read_ahead_kb is expressed in KiB rather than sectors, so 8 sets the same 8 KiB read-ahead as blockdev --setra 16. Device names alone do not distinguish SSDs from HDDs (both appear as sd*), so the rules below match on queue/rotational to apply 8 KiB to SSDs and 64 KiB to HDDs; NVMe devices always report as non-rotational, so the rule applies the 8 KiB value directly without a rotational match.

/etc/udev/rules.d/60-cassandra.rules
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/scheduler}="mq-deadline"
# read_ahead_kb is in KiB: rotational "0" = SSD (8 KiB), "1" = HDD (64 KiB)
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/read_ahead_kb}="8"
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/read_ahead_kb}="64"
ACTION=="add|change", KERNEL=="nvme[0-9]*", ATTR{queue/scheduler}="none"
ACTION=="add|change", KERNEL=="nvme[0-9]*", ATTR{queue/read_ahead_kb}="8"

Reload the rules and re-trigger device events to apply the settings to running devices, then confirm the result:

Terminal window
udevadm control --reload-rules && udevadm trigger
cat /sys/block/sda/queue/read_ahead_kb # expect 8 (SSD) or 64 (HDD)
cat /sys/block/nvme0n1/queue/read_ahead_kb # expect 8

Swap pages anonymous memory, including the JVM heap, to disk under memory pressure. For Cassandra this produces latency spikes and long GC pauses, so swap should be disabled. vm.swappiness is then set as a safeguard for hosts where swap cannot be removed. See Linux Memory Configuration for the full rationale.

Terminal window
# Primary: disable swap, and remove swap entries from /etc/fstab so it stays off
swapoff -a
# Safeguard: minimise swapping where swap cannot be removed (use 1, never 0;
# since kernel 3.5 a value of 0 stops swapping even under pressure and raises
# the risk of an OOM kill)
echo 1 > /proc/sys/vm/swappiness
# Persistent
echo "vm.swappiness = 1" >> /etc/sysctl.conf
Terminal window
# Disable zone reclaim for NUMA
echo 0 > /proc/sys/vm/zone_reclaim_mode
/etc/sysctl.conf
vm.dirty_background_ratio = 5
vm.dirty_ratio = 80

Cassandra memory-maps SSTable files, so vm.max_map_count must be raised above the Linux default of 65530. In Cassandra 4.0, 4.1, and 5.0 a startup check warns when the value is below 1048575, so set it to at least that on every node.

/etc/sysctl.conf
vm.max_map_count = 1048575

See Linux Memory Configuration for the startup-check detail.

/etc/sysctl.conf
# Increase socket buffer sizes
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.rmem_default = 16777216
net.core.wmem_default = 16777216
net.core.optmem_max = 40960
# TCP buffers
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
# Connection handling
net.core.netdev_max_backlog = 50000
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 30000
# Timeouts
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_keepalive_time = 60
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl = 10
Terminal window
sysctl -p
/etc/security/limits.conf
cassandra soft nofile 100000
cassandra hard nofile 100000
cassandra soft nproc 32768
cassandra hard nproc 32768
cassandra soft memlock unlimited
cassandra hard memlock unlimited
cassandra soft as unlimited
cassandra hard as unlimited
Terminal window
# As cassandra user
ulimit -n # File descriptors
ulimit -u # Processes
ulimit -l # Memory lock

Disable THP - causes latency spikes with Cassandra.

Terminal window
# Check current status
cat /sys/kernel/mm/transparent_hugepage/enabled
cat /sys/kernel/mm/transparent_hugepage/defrag
# Disable
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag

The script below suits /etc/rc.local or a tuned profile:

/etc/rc.local
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

For a systemd unit, use a oneshot service ordered Before=cassandra.service so THP is disabled before Cassandra starts; a bare service without that ordering can run after the JVM has begun allocating. The complete ordered unit is in Linux Memory Configuration.

Terminal window
# Set to performance
for cpu in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
echo performance > $cpu
done
# Verify
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
Terminal window
# Verify NUMA topology
numactl --hardware
# Run Cassandra with NUMA awareness
numactl --interleave=all cassandra

Filesystem selection significantly impacts Cassandra performance, particularly for commit log operations. The choice between XFS and ext4 depends on workload characteristics and Linux distribution.

Quick recommendations:

Use CaseFilesystemNotes
Data directoriesXFSOptimized for large files and parallel I/O
Commit logsext4 or XFS + compressionext4 has better memory-mapped I/O performance

→ Filesystem Selection Guide - Complete architecture comparison, benchmarks, and configuration

Basic mount options:

Terminal window
# XFS for data
/dev/sdb1 /var/lib/cassandra/data xfs defaults,noatime,nodiratime 0 2
# ext4 for commit logs
/dev/sdc1 /var/lib/cassandra/commitlog ext4 defaults,noatime,nodiratime 0 2
cassandra-os-tuning.sh
#!/bin/bash
# Disable swap
swapoff -a
# Disable THP
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo never > /sys/kernel/mm/transparent_hugepage/defrag
# Set swappiness
sysctl -w vm.swappiness=0
# Disk scheduler (adjust device names)
echo deadline > /sys/block/sda/queue/scheduler
# Apply sysctl settings
sysctl -p
echo "OS tuning applied"