nodetool setcompactionthroughput
Sets the total compaction throughput limit across all compaction threads on a node.
Synopsis
Section titled “Synopsis”nodetool [connection_options] setcompactionthroughput <throughput_mb_per_sec>See connection options for connection options.
Description
Section titled “Description”nodetool setcompactionthroughput controls the maximum rate at which all compaction operations combined can write data to disk. This throttle prevents compaction from consuming too much disk I/O and impacting production read/write workloads.
Total Throughput, Not Per-Thread
Section titled “Total Throughput, Not Per-Thread”Aggregate Limit
The throughput limit is the total aggregate limit across all concurrent compaction threads, not a per-thread limit.
For example, with concurrent_compactors: 4 and throughput set to 128 MiB/s:
- All 4 compaction threads share the 128 MiB/s budget
- Each thread averages approximately 32 MiB/s (128 ÷ 4)
- The actual distribution varies based on workload
Non-Persistent Setting
This setting is applied at runtime only and does not persist across node restarts. After a restart, the value reverts to the compaction_throughput setting in cassandra.yaml (default: 64 MiB/s).
To make the change permanent, update cassandra.yaml:
compaction_throughput: 128MiB/sArguments
Section titled “Arguments”| Argument | Description |
|---|---|
throughput_mib_per_sec | Maximum MiB/s for all compaction writes combined. 0 = unlimited |
cassandra.yaml Parameter
The corresponding cassandra.yaml parameter changed in 4.1:
| Cassandra Version | Parameter Name | Example |
|---|---|---|
| Pre-4.1 | compaction_throughput_mb_per_sec | 64 |
| 4.1+ | compaction_throughput | 64MiB/s |
Examples
Section titled “Examples”Set Throughput to 128 MiB/s
Section titled “Set Throughput to 128 MiB/s”nodetool setcompactionthroughput 128Remove Throttling (Unlimited)
Section titled “Remove Throttling (Unlimited)”nodetool setcompactionthroughput 0Check Current Setting
Section titled “Check Current Setting”nodetool getcompactionthroughputWhen to Adjust Compaction Throughput
Section titled “When to Adjust Compaction Throughput”Scenario 1: Compaction Backlog Growing
Section titled “Scenario 1: Compaction Backlog Growing”Symptoms:
nodetool compactionstatsshows increasing pending compactions- SSTable counts rising over time
- Read latencies gradually increasing
Action: Increase throughput to help compaction keep pace:
# Check current pending compactionsnodetool compactionstats
# Check current throughputnodetool getcompactionthroughput
# Increase throughputnodetool setcompactionthroughput 256
# Monitor progresswatch -n 10 'nodetool compactionstats'Scenario 2: Production Latencies Spiking During Compaction
Section titled “Scenario 2: Production Latencies Spiking During Compaction”Symptoms:
- Read/write latencies spike when compaction is active
- Disk I/O at or near 100% utilization
- Application timeouts correlate with compaction activity
Action: Decrease throughput to reduce I/O contention:
# Check if compaction is runningnodetool compactionstats
# Reduce throughput to ease disk pressurenodetool setcompactionthroughput 64
# Monitor latenciesnodetool proxyhistogramsScenario 3: Maintenance Window - Clear Backlog
Section titled “Scenario 3: Maintenance Window - Clear Backlog”Symptoms:
- Scheduled maintenance with reduced traffic
- Need to clear compaction backlog before peak hours
Action: Temporarily maximize throughput:
# Remove throttle during maintenancenodetool setcompactionthroughput 0
# Or set very high valuenodetool setcompactionthroughput 1024
# Wait for compactions to completewatch -n 10 'nodetool compactionstats'
# Restore normal throttle before traffic returnsnodetool setcompactionthroughput 128Scenario 4: After Bulk Data Load
Section titled “Scenario 4: After Bulk Data Load”Symptoms:
- Large amount of data just loaded
- Many SSTables created, pending compaction
Action: Increase throughput to consolidate data faster:
# After bulk load completesnodetool setcompactionthroughput 512
# Monitor compaction progressnodetool compactionstats
# Once caught up, restore normal valuenodetool setcompactionthroughput 128Scenario 5: Disk Space Running Low
Section titled “Scenario 5: Disk Space Running Low”Symptoms:
- Disk usage approaching capacity
- Compaction can free space by removing tombstones/overwrites
Action: Increase throughput to accelerate space reclamation:
# Check disk spacedf -h /var/lib/cassandra
# Increase compaction speednodetool setcompactionthroughput 512
# Optionally trigger compaction on specific tablesnodetool compact my_keyspace my_tablePerformance Metrics to Monitor
Section titled “Performance Metrics to Monitor”Before Adjusting Throughput
Section titled “Before Adjusting Throughput”Gather baseline metrics to understand current state:
#!/bin/bash# baseline_metrics.sh - Capture before changing throughput
echo "=== Current Compaction Throughput ==="nodetool getcompactionthroughput
echo ""echo "=== Pending Compactions ==="nodetool compactionstats
echo ""echo "=== SSTable Counts (top 10 tables) ==="nodetool tablestats | grep -E "Table:|SSTable count" | head -20
echo ""echo "=== Disk I/O ==="iostat -x 1 3 | tail -10
echo ""echo "=== Read/Write Latencies ==="nodetool proxyhistogramsKey Metrics to Watch
Section titled “Key Metrics to Watch”| Metric | How to Check | What to Look For |
|---|---|---|
| Pending compactions | nodetool compactionstats | Should decrease after increasing throughput |
| Disk I/O utilization | iostat -x 1 | %util should not sustain 100% |
| Disk I/O await | iostat -x 1 | await (ms) indicates I/O latency |
| Read latency | nodetool proxyhistograms | 99th percentile read latency |
| Write latency | nodetool proxyhistograms | 99th percentile write latency |
| SSTable count | nodetool tablestats | Should decrease as compaction catches up |
| Compaction throughput | nodetool compactionstats | Actual MiB/s being written |
Monitoring During Adjustment
Section titled “Monitoring During Adjustment”#!/bin/bash# monitor_compaction.sh - Watch key metrics in real-time
while true; do clear echo "=== $(date) ===" echo ""
echo "--- Compaction Status ---" nodetool compactionstats | head -15 echo ""
echo "--- Disk I/O ---" iostat -x 1 1 | grep -E "Device|sda|nvme" | tail -2 echo ""
echo "--- Recent Latencies ---" nodetool proxyhistograms | head -10
sleep 10doneWarning Signs
Section titled “Warning Signs”| Observation | Problem | Action |
|---|---|---|
| Disk %util consistently 100% | I/O saturated | Decrease throughput |
| await > 20ms (SSD) or > 100ms (HDD) | I/O congestion | Decrease throughput |
| Read 99th percentile spiking | Compaction impacting reads | Decrease throughput |
| Pending compactions growing | Throughput too low | Increase throughput |
| SSTable count rising steadily | Compaction can't keep up | Increase throughput |
Recommended Values by Storage Type
Section titled “Recommended Values by Storage Type”| Storage Type | Default | Conservative | Aggressive | Notes |
|---|---|---|---|---|
| HDD (7200 RPM) | 64 MiB/s | 32 MiB/s | 128 MiB/s | Limited by seek time, be conservative |
| HDD (15K RPM) | 64 MiB/s | 48 MiB/s | 160 MiB/s | Slightly better than 7200 RPM |
| SATA SSD | 128 MiB/s | 64 MiB/s | 256 MiB/s | Good baseline for most SSDs |
| NVMe SSD | 256 MiB/s | 128 MiB/s | 512+ MiB/s | Can handle much higher throughput |
| Cloud (EBS gp3) | 128 MiB/s | 64 MiB/s | Provisioned IOPS | Depends on provisioned performance |
| Cloud (local NVMe) | 256 MiB/s | 128 MiB/s | 512+ MiB/s | Similar to on-prem NVMe |
Tuning Approach
Section titled “Tuning Approach”# 1. Start with default or conservative valuenodetool setcompactionthroughput 64
# 2. Monitor disk utilization and latenciesiostat -x 5nodetool proxyhistograms
# 3. If disk has headroom (util < 70%), increasenodetool setcompactionthroughput 128
# 4. Continue monitoring# 5. If latencies spike, back offnodetool setcompactionthroughput 96
# 6. Find the sweet spot where:# - Compaction keeps pace (pending not growing)# - Disk not saturated (util < 80%)# - Latencies acceptableImpact Analysis
Section titled “Impact Analysis”Effects of Different Throughput Settings
Section titled “Effects of Different Throughput Settings”Finding the Right Balance
Section titled “Finding the Right Balance”The optimal throughput balances:
- Compaction keeping pace - Pending compactions not growing
- Acceptable latencies - Production traffic not impacted
- Disk headroom - I/O utilization not saturated
# Good balance indicators:# - Pending compactions: stable or decreasing# - Disk I/O util: 50-70%# - Read p99: within SLA# - Write p99: within SLAConcurrent Compactors Interaction
Section titled “Concurrent Compactors Interaction”The throughput limit interacts with the number of concurrent compactors:
concurrent_compactors: 4 # Number of parallel compaction threadscompaction_throughput: 128MiB/s # Total throughput for all threads| concurrent_compactors | throughput | Per-Thread Average |
|---|---|---|
| 2 | 128 MiB/s | ~64 MiB/s |
| 4 | 128 MiB/s | ~32 MiB/s |
| 8 | 128 MiB/s | ~16 MiB/s |
| 4 | 256 MiB/s | ~64 MiB/s |
| 4 | 512 MiB/s | ~128 MiB/s |
Balancing Threads and Throughput
More compactors with the same throughput means each individual compaction runs slower, but more compactions run in parallel. The total throughput remains capped.
For CPU-bound compaction (compression), more threads can help. For I/O-bound compaction, the throughput limit is the bottleneck.
Cluster-Wide Configuration
Section titled “Cluster-Wide Configuration”Apply to All Nodes
Section titled “Apply to All Nodes”#!/bin/bashTHROUGHPUT="${1:-128}"
# Get list of node IPs from local nodetool statusnodes=$(nodetool status | grep "^UN" | awk '{print $2}')
echo "Setting compaction throughput to $THROUGHPUT MiB/s on all nodes..."
for node in $nodes; do echo -n "$node: " ssh "$node" 'nodetool setcompactionthroughput '"$THROUGHPUT"' && echo "set to '"$THROUGHPUT"' MiB/s" || echo "FAILED"'done
echo ""echo "Verification:"for node in $nodes; do echo -n "$node: " ssh "$node" "nodetool getcompactionthroughput"doneMaking Changes Permanent
Section titled “Making Changes Permanent”# cassandra.yaml - applies after restartcompaction_throughput: 128MiB/sTroubleshooting
Section titled “Troubleshooting”Throughput Seems Limited Despite High Setting
Section titled “Throughput Seems Limited Despite High Setting”# Check actual compaction throughput in compactionstatsnodetool compactionstats# Look for "throughput" in output
# May be limited by:# 1. Disk I/O capacity# 2. CPU (if heavy compression)# 3. No compactions pending
# Check disk I/Oiostat -x 1 5Compaction Still Slow After Increasing Throughput
Section titled “Compaction Still Slow After Increasing Throughput”# Check if compactions are actually runningnodetool compactionstats
# Check if disk is the bottleneckiostat -x 1 3
# Check if CPU is bottleneck (compression)top -H -p $(pgrep -f CassandraDaemon)
# May need to increase concurrent_compactors instead# (requires cassandra.yaml change and restart)Setting Reverted After Restart
Section titled “Setting Reverted After Restart”# Runtime setting doesn't persist# Check cassandra.yamlgrep compaction_throughput /etc/cassandra/cassandra.yaml
# Update for persistence# Then restart or set runtime valueBest Practices
Section titled “Best Practices”Throughput Guidelines
- Monitor before changing - Establish baseline metrics
- Adjust incrementally - Change by 50-100% at a time, not 10x
- Watch disk I/O - Keep utilization below 80%
- Check latencies - Ensure production traffic isn't impacted
- Time it right - Make aggressive changes during low-traffic periods
- Make permanent - Update
cassandra.yamlafter validating changes - Apply cluster-wide - Set same value on all nodes for consistency
Avoid These Mistakes
- Setting unlimited (0) during peak traffic
- Ignoring disk I/O metrics when increasing throughput
- Forgetting to persist changes to
cassandra.yaml - Setting different values on different nodes (causes imbalance)
Related Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| getcompactionthroughput | View current throughput setting |
| compactionstats | Monitor active and pending compactions |
| setconcurrentcompactors | Adjust number of compaction threads |
| setstreamthroughput | Control streaming throughput (different from compaction) |
| tablestats | View SSTable counts per table |
| proxyhistograms | Check read/write latencies |