Operating System Tuning for Cassandra
Optimize your Linux operating system for Cassandra performance.
Disk I/O Settings
Section titled “Disk I/O Settings”Scheduler
Section titled “Scheduler”# Check current schedulercat /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 NVMeecho none > /sys/block/nvme0n1/queue/schedulerRead-Ahead
Section titled “Read-Ahead”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.
# 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/sdaPersistent Configuration
Section titled “Persistent Configuration”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.
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:
udevadm control --reload-rules && udevadm triggercat /sys/block/sda/queue/read_ahead_kb # expect 8 (SSD) or 64 (HDD)cat /sys/block/nvme0n1/queue/read_ahead_kb # expect 8Memory Settings
Section titled “Memory Settings”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.
# Primary: disable swap, and remove swap entries from /etc/fstab so it stays offswapoff -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
# Persistentecho "vm.swappiness = 1" >> /etc/sysctl.confZone Reclaim
Section titled “Zone Reclaim”# Disable zone reclaim for NUMAecho 0 > /proc/sys/vm/zone_reclaim_modeDirty Pages
Section titled “Dirty Pages”vm.dirty_background_ratio = 5vm.dirty_ratio = 80Memory Map Limit
Section titled “Memory Map Limit”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.
vm.max_map_count = 1048575See Linux Memory Configuration for the startup-check detail.
Network Tuning
Section titled “Network Tuning”TCP Settings
Section titled “TCP Settings”# Increase socket buffer sizesnet.core.rmem_max = 16777216net.core.wmem_max = 16777216net.core.rmem_default = 16777216net.core.wmem_default = 16777216net.core.optmem_max = 40960
# TCP buffersnet.ipv4.tcp_rmem = 4096 87380 16777216net.ipv4.tcp_wmem = 4096 65536 16777216
# Connection handlingnet.core.netdev_max_backlog = 50000net.core.somaxconn = 65535net.ipv4.tcp_max_syn_backlog = 30000
# Timeoutsnet.ipv4.tcp_fin_timeout = 10net.ipv4.tcp_keepalive_time = 60net.ipv4.tcp_keepalive_probes = 3net.ipv4.tcp_keepalive_intvl = 10Apply Changes
Section titled “Apply Changes”sysctl -pFile Descriptors
Section titled “File Descriptors”Limits
Section titled “Limits”cassandra soft nofile 100000cassandra hard nofile 100000cassandra soft nproc 32768cassandra hard nproc 32768cassandra soft memlock unlimitedcassandra hard memlock unlimitedcassandra soft as unlimitedcassandra hard as unlimitedVerify
Section titled “Verify”# As cassandra userulimit -n # File descriptorsulimit -u # Processesulimit -l # Memory lockTransparent Huge Pages
Section titled “Transparent Huge Pages”Disable THP - causes latency spikes with Cassandra.
# Check current statuscat /sys/kernel/mm/transparent_hugepage/enabledcat /sys/kernel/mm/transparent_hugepage/defrag
# Disableecho never > /sys/kernel/mm/transparent_hugepage/enabledecho never > /sys/kernel/mm/transparent_hugepage/defragPersistent Disable
Section titled “Persistent Disable”The script below suits /etc/rc.local or a tuned profile:
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then echo never > /sys/kernel/mm/transparent_hugepage/enabledfiif test -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defragfiFor 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.
CPU Settings
Section titled “CPU Settings”CPU Governor
Section titled “CPU Governor”# Set to performancefor cpu in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo performance > $cpudone
# Verifycat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor# Verify NUMA topologynumactl --hardware
# Run Cassandra with NUMA awarenessnumactl --interleave=all cassandraFilesystem
Section titled “Filesystem”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 Case | Filesystem | Notes |
|---|---|---|
| Data directories | XFS | Optimized for large files and parallel I/O |
| Commit logs | ext4 or XFS + compression | ext4 has better memory-mapped I/O performance |
→ Filesystem Selection Guide - Complete architecture comparison, benchmarks, and configuration
Basic mount options:
# 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 2Complete Configuration Script
Section titled “Complete Configuration Script”#!/bin/bash# Disable swapswapoff -a
# Disable THPecho never > /sys/kernel/mm/transparent_hugepage/enabledecho never > /sys/kernel/mm/transparent_hugepage/defrag
# Set swappinesssysctl -w vm.swappiness=0
# Disk scheduler (adjust device names)echo deadline > /sys/block/sda/queue/scheduler
# Apply sysctl settingssysctl -p
echo "OS tuning applied"Next Steps
Section titled “Next Steps”- Filesystem Selection - XFS vs ext4 architecture and recommendations
- JVM Tuning - JVM optimization
- Hardware - Hardware sizing
- Performance Overview - Performance guide