Cassandra JVM Options
Most deployments need no JVM tuning. On Cassandra 5.0, 4.1 and 4.0 the installation already sizes the heap, the region of memory the JVM allocates objects in, from host memory; configures a garbage collector, the component that reclaims heap no longer in use; writes a rotating GC log; and takes a heap dump if the JVM runs out of memory. None of that requires an edit to the files described below.
The shipped configuration is only part of why tuning is rarely needed. Cassandra keeps its large, long-lived data structures off the JVM heap: bloom filters, the partition index summary, compression metadata, the chunk cache, networking buffers, and the memtables themselves where memtable_allocation_type selects an off-heap mode. Data of that size and lifetime is what dominates a collection cycle when it sits on the heap, so holding it off the heap leaves the collector a much smaller live set to trace. Off-heap memory is not free: it is still allocated by the process and still counts against host memory, which is why direct memory carries a bound of its own. How Cassandra Uses Off-Heap Memory lists what is held there, and Memory Management introduces the pools a node divides its memory into.
Garbage collection can still become the constraint on a node, and JVM Tuning covers that case in full, but arriving there should follow a measurement taken on the node rather than a rule of thumb carried in from another cluster.
Cassandra builds its JVM command line from two sources: the options files in the configuration directory, and cassandra-env.sh, which computes several settings when the node starts and appends them. This page covers which file holds what, what the installation already provides, and the few settings worth reviewing before a cluster goes into service.
Options Files
Section titled “Options Files”| File | Read when | Holds |
|---|---|---|
jvm-server.options | Always | Settings that apply to every supported JDK: thread stack size, heap dump behaviour, and the commented -Xmx and -Xms pair |
jvm11-server.options | The daemon runs on JDK 11 | The garbage collector and its settings for JDK 11 |
jvm17-server.options | The daemon runs on JDK 17, which 5.0 supports and 4.1 and 4.0 do not | The garbage collector and its settings for JDK 17 |
The packaged location is /etc/cassandra/. Exactly one per-JDK file is read, chosen by the JDK the daemon starts under, which is why the same jvm-server.options produces different collector behaviour on different JDKs. A 5.0 node started under JDK 17 reads jvm17-server.options and ignores jvm11-server.options entirely.
The set of files differs by release. 5.0 ships jvm-server.options, jvm11-server.options and jvm17-server.options. 4.1 and 4.0 support JDK 11 and ship jvm-server.options, jvm8-server.options and jvm11-server.options; neither carries a jvm17-server.options. Each release also ships a -clients variant of every file, read by the tools rather than by the daemon.
Running 5.0 under JDK 17 needs no module flags added by hand: jvm17-server.options already carries the --add-opens and --add-exports entries the process requires.
Where the Heap Is Set
Section titled “Where the Heap Is Set”The heap is in none of these files. cassandra-env.sh computes -Xms and -Xmx from host memory at start and appends them to the command line, so searching jvm-server.options for -Xmx on a default install finds only a commented pair. The computed value differs by release, and it changed inside 5.0 at 5.0.4 (CASSANDRA-20296).
Heap Sizing holds the formula for each release, the resulting heap for each host size, and the two supported ways to override it. A heap value carried over from a 4.x cluster is not a starting point for a node on 5.0.4 or later, because the two formulas diverge as host memory grows.
What the Installation Provides
Section titled “What the Installation Provides”These are active on a default install of 5.0, 4.1 and 4.0. None of them needs an edit to take effect, and re-adding one changes nothing.
| Provided | State on the shipped configuration | Detail |
|---|---|---|
| Heap size | Computed from host memory by cassandra-env.sh at every start | Heap Sizing |
| Garbage collector | The Garbage-First collector (G1) active on 5.0 (CASSANDRA-18027); the Concurrent Mark Sweep collector (CMS) active on 4.1 and 4.0, with a full G1 block commented out in the same file | Collector by Version |
| Direct memory bound | A limit on direct memory, the pool outside the heap that holds network and compression buffers. -XX:MaxDirectMemorySize is set to half the max heap on 5.0.4 and later; it is not set on 5.0.0 to 5.0.3, 4.1 and 4.0, where the JVM defaults it to the max heap | Direct Memory |
| GC logging | -Xlog:gc to $CASSANDRA_LOG_DIR/gc.log, 10 files of 10MiB | GC Logging |
| Heap dump on out of memory | -XX:+HeapDumpOnOutOfMemoryError active in jvm-server.options | Heap dump location below |
| Action on out of memory | -XX:OnOutOfMemoryError=kill -9 %p, appended by cassandra-env.sh | Recover from OOM |
jvm-server.options also ships -Xss256k, which fixes the thread stack size, and -XX:+AlwaysPreTouch, which touches every heap page at start so the heap is resident from the first request rather than faulted in under load.
The packages install an LSB SysV init script and no systemd unit, so nothing restarts the process after the out-of-memory kill. Restart handling is the operator’s on all three releases, whatever the out-of-memory action.
Settings Worth Reviewing
Section titled “Settings Worth Reviewing”Two settings are worth a decision on a new cluster. Everything else on a default install can be left alone until a measurement says otherwise.
CASSANDRA_HEAPDUMP_DIR, set in the environment, controls where the out-of-memory heap dump is written. A dump holds the live contents of the heap, so it can approach the size of -Xmx: a node with a 16G heap can write a file of that order in one go. On 5.0.4 and later the destination defaults to the log directory, which is /var/log/cassandra in the packaged layout, so a dump can fill the filesystem that also holds system.log and stop the node logging. Point it at a filesystem with room for a full heap.
cassandra-env.sh appends -XX:HeapDumpPath on every start on 5.0.4 and later, from CASSANDRA_HEAPDUMP_DIR or from the log directory when that variable is unset. A path set in an options file on those versions is therefore overridden, and CASSANDRA_HEAPDUMP_DIR is the setting that takes effect. On 5.0.0 to 5.0.3, 4.1 and 4.0 the script appends -XX:HeapDumpPath only when CASSANDRA_HEAPDUMP_DIR is set; with it unset the JVM writes the dump to the working directory of the process.
GC log retention is 10 files of 10MiB on 5.0, 4.1 and 4.0, so the log holds 100MiB before the oldest file is discarded. How long that covers depends on collection frequency on the node. Where an investigation needs a longer window, the retention is raised by writing an explicit -Xlog:gc line in an options file. Mentioning -Xlog:gc there replaces the shipped configuration rather than adding to it, so the replacement line must carry its own file, rotation and decorator settings; GC Logging gives the full line. The cost is disk: raising the count or size consumes more of the filesystem that holds system.log.
Reading the Effective Configuration
Section titled “Reading the Effective Configuration”An options file records intent. The command line of the running process records what took effect, including everything cassandra-env.sh appended. What the Release Already Sets gives the ps command that prints it, alongside the values each release supplies.
One reading needs no command line at all:
nodetool info | grep "Heap Memory"That reports the max and used heap as the JVM itself sees them, which is the quickest confirmation that a heap change took effect.
A node reporting a collector other than the one its release starts with has been configured by hand. Settings for a collector the node is not running are ignored, so a file carrying two active collector blocks records a configuration that is not in effect.
Changing an Options File
Section titled “Changing an Options File”Every setting in these files takes effect at the next start of the node; none can be changed on a running JVM. Restart one node at a time, and keep a copy of the previous file so a change can be rolled back by restoring it. Applying and Validating a Change gives the full procedure, the measurements to record either side of it, and how to judge whether the change helped.
-Xms and -Xmx in jvm-server.options must both be present or both absent; setting one alone stops the node starting with a message asking for the pair. The heap can also be set through the environment, where the same pairing rule applies to MAX_HEAP_SIZE and HEAP_NEWSIZE under any collector other than G1. Changing the Heap covers both mechanisms.
Going Further
Section titled “Going Further”The advanced material is on JVM Tuning and its collector pages. Each section answers a different question:
- Heap Sizing - what the computed heap is on a given host and release, and how to pin a different value where a measured collection profile calls for one.
- G1 and CMS - the settings each collector runs with, and what changing each one costs. Read these when the GC log shows pauses that matter to request latency, or on 4.1 and 4.0 when deciding between the two, since both releases carry a complete G1 block alongside the CMS one they start with.
- Shenandoah and ZGC - collectors that appear in no options file and are supplied by the operator. Read the Shenandoah page when pauses under G1 remain the constraint after tuning it: AxonOps recommends Shenandoah over G1 for Cassandra, and recommends Azul Zulu Builds of OpenJDK, which carry the collector. Read the ZGC page before enabling ZGC, for the project position and the JDK constraints.
- Direct Memory - the pool outside the heap that holds network and compression buffers, and the usual explanation for a container killed by the kernel while the JVM reports a healthy heap.
- Applying and Validating a Change - the measurements to record before and after, and how to decide whether a change was an improvement.
Related Documentation
Section titled “Related Documentation”- JVM Tuning - Heap values per version and host size, collector settings, and how to change them
- JVM Architecture - Why the defaults are what they are, and where the heap sits in process memory
- cassandra.yaml - Main configuration
- Performance Tuning - Host and workload settings outside the JVM
- Monitoring - JVM monitoring
- Recover from OOM - Diagnosis after a node is lost to memory exhaustion