JVM Tuning for Cassandra
Optimize JVM settings for optimal Cassandra performance.
Heap Configuration
Section titled “Heap Configuration”Sizing Guidelines
Section titled “Sizing Guidelines”| System RAM | Heap Size | Notes |
|---|---|---|
| 8GB | 4GB | Development only |
| 32GB | 8GB | Small production |
| 64GB | 16GB | Standard production |
| 128GB+ | 31GB | Maximum recommended |
Key Rules:
- Never exceed 31GB (compressed oops limit)
- Leave 50%+ RAM for OS page cache
- Set
-Xmsequal to-Xmx
Configuration
Section titled “Configuration”# jvm11-server.options or jvm17-server.options
# Heap size (adjust for your system)-Xms16G-Xmx16GGarbage Collection
Section titled “Garbage Collection”G1GC (Default, Recommended)
Section titled “G1GC (Default, Recommended)”# G1GC Configuration-XX:+UseG1GC-XX:MaxGCPauseMillis=500-XX:G1RSetUpdatingPauseTimePercent=5-XX:InitiatingHeapOccupancyPercent=70-XX:ParallelGCThreads=16-XX:ConcGCThreads=4-XX:+ParallelRefProcEnabled-XX:MaxTenuringThreshold=1-XX:G1HeapWastePercent=10ZGC (Low Latency)
Section titled “ZGC (Low Latency)”# ZGC for ultra-low latency-XX:+UseZGC
# ZGenerational is available in JDK 21+ only# -XX:+ZGenerational
-XX:SoftMaxHeapSize=28G-XX:ZCollectionInterval=0ZGC Version Requirements
- JDK 11-16: ZGC is experimental (
-XX:+UnlockExperimentalVMOptionsrequired) - JDK 17-20: ZGC is production-ready (non-generational)
- JDK 21+: ZGenerational mode available via
-XX:+ZGenerational
Shenandoah (JDK 11+, Alternative)
Section titled “Shenandoah (JDK 11+, Alternative)”# Shenandoah GC-XX:+UseShenandoahGC-XX:ShenandoahGCHeuristics=compactGC Logging
Section titled “GC Logging”JDK 11+ Format
Section titled “JDK 11+ Format”# Comprehensive GC logging-Xlog:gc*:file=/var/log/cassandra/gc.log:time,uptime,level,tags:filecount=10,filesize=10M-Xlog:safepoint:file=/var/log/cassandra/safepoint.log:time,uptime:filecount=5,filesize=5MMemory Settings
Section titled “Memory Settings”Metaspace
Section titled “Metaspace”-XX:MetaspaceSize=128M-XX:MaxMetaspaceSize=256MDirect Memory (Off-Heap)
Section titled “Direct Memory (Off-Heap)”# For memtable_offheap and file cache-XX:MaxDirectMemorySize=4GThread Stack
Section titled “Thread Stack”# Reduce stack size for many threads-Xss256kPerformance Optimizations
Section titled “Performance Optimizations”String Optimization
Section titled “String Optimization”# String deduplication (G1GC only)-XX:+UseStringDeduplication-XX:StringDeduplicationAgeThreshold=1Compilation
Section titled “Compilation”# Tiered compilation (default)-XX:+TieredCompilation
# Code cache-XX:ReservedCodeCacheSize=256M-XX:+UseCodeCacheFlushingDisable Explicit GC
Section titled “Disable Explicit GC”# Prevent application-triggered GC-XX:+DisableExplicitGCDebugging and Monitoring
Section titled “Debugging and Monitoring”Heap Dumps
Section titled “Heap Dumps”# Automatic heap dump on OOM-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=/var/lib/cassandra/
# Exit on OOM (let orchestrator restart)-XX:+ExitOnOutOfMemoryErrorJMX (if external)
Section titled “JMX (if external)”-Djava.rmi.server.hostname=<node_ip>-Dcom.sun.management.jmxremote.port=7199-Dcom.sun.management.jmxremote.ssl=false-Dcom.sun.management.jmxremote.authenticate=falseComplete Configuration Example
Section titled “Complete Configuration Example”###################### HEAP CONFIGURATION#####################-Xms16G-Xmx16G
###################### GC CONFIGURATION#####################-XX:+UseG1GC-XX:MaxGCPauseMillis=500-XX:InitiatingHeapOccupancyPercent=70-XX:ParallelGCThreads=16-XX:ConcGCThreads=4-XX:+ParallelRefProcEnabled-XX:MaxTenuringThreshold=1-XX:G1HeapWastePercent=10-XX:+UseStringDeduplication
###################### GC LOGGING#####################-Xlog:gc*:file=/var/log/cassandra/gc.log:time,uptime:filecount=10,filesize=10M
###################### MEMORY#####################-XX:MetaspaceSize=128M-XX:MaxMetaspaceSize=256M-XX:MaxDirectMemorySize=4G-Xss256k
###################### ERROR HANDLING#####################-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=/var/lib/cassandra/-XX:+ExitOnOutOfMemoryError
###################### PERFORMANCE#####################-XX:+DisableExplicitGC-XX:+AlwaysPreTouch-XX:+UseLargePagesTuning by Workload
Section titled “Tuning by Workload”| Workload | Heap | GC | Key Settings |
|---|---|---|---|
| Write-heavy | 16-24GB | G1GC | Higher IHOP (75%) |
| Read-heavy | 16-31GB | G1GC | Lower pause target |
| Low latency | 16GB | ZGC | -XX:+UseZGC |
| Mixed | 16GB | G1GC | Default settings |
Monitoring GC
Section titled “Monitoring GC”# Check GC activitynodetool gcstats
# Watch GC logstail -f /var/log/cassandra/gc.logNext Steps
Section titled “Next Steps”- OS Tuning - Operating system optimization
- Hardware - Hardware recommendations
- JVM Options - Complete options reference