Changing heap size parameters
Adjust the minimum, maximum and new generation heap sizes to tune JVM.
max(min(1/2 ram, 1024 megabytes), min(1/4 ram, 32765 megabytes))
- Minimum (
-Xms
) - Maximum (
-Xmx
) - New generation (
-Xmn
) - Parallel processing for GC (
-XX:+UseParallelGC
)
Additionally,
for larger machines, increase the max direct memory
(-XX:MaxDirectMemorySize
), but leave around 15-20% of memory
for the OS and other in-memory structures.
jvm.options
The location of the jvm.options file depends on the type of installation:
Package installations |
/etc/dse/cassandra/jvm.options |
Tarball installations |
installation_location/resources/cassandra/conf/jvm.options |
cassandra-env.sh
- The cassandra-env.sh file is located in the installation_location/conf directory.
Guidelines and recommendations
Setting the Java heap higher than 32 GB may interfere with the OS page cache. Operating systems that maintain the OS page cache for frequently accessed data are very good at keeping this data in memory. Properly tuning the OS page cache usually results in better performance than increasing the row cache.
- Heap size is usually between ¼ and ½ of system memory but not larger than 32 GB.
- Reserve enough memory for the offheap cache and file system cache.
- Enable GC logging when adjusting GC.
- Gradually increase or decrease the parameters. Test each incremental change.
- The GCInspector class logs information about any garbage collection that takes longer than 200 ms. Garbage collections that occur frequently and take a moderate length of time (seconds) to complete indicate excessive garbage collection pressure on the JVM. In addition to adjusting the garbage collection options, other remedies include adding nodes, and lowering cache sizes.
- For a node using G1, DataStax recommends a
MAX_HEAP_SIZE
as large as possible, up to 64 GB.
Maximum and minimum heap size
Hardware setup | Recommended MAX_HEAP_SIZE |
---|---|
G1 for newer computers (8+ cores) with up to 256 GB RAM | 16 GB to 32 GB |
CMS for newer computers (8+ cores) with up to 256 GB RAM | No more than 16 GB |
Older computers | Typically 8 GB |
New heap size
- 100 times the number of cores
- ¼ of MAX_HEAP_SIZE
Procedure
-
To enable GC logging, uncomment the
loggc
parameter in the jvm.options file.-Xloggc:/var/log/cassandra/gc.log
After restarting Cassandra the log is created and GC events are recorded. -
Set the heap sizes in the jvm.options
file:
-
On larger machines, increase the max direct memory
(
-XX:MaxDirectMemorySize
), but leave around 15-20% of memory for the OS and other in-memory structures. For example, to set the max direct memory to 1 MB:-XX:MaxDirectMemorySize=1M
By default, the size is zero, so the JVM selects the size of the NIO direct-buffer allocations automatically.
Tip: Alternatively, you can set an environment variable calledMAX_DIRECT_MEM
, instead of setting a size for-XX:MaxDirectMemorySize
in the jvm.options file. - Save and close the jvm.options file.
- Restart Cassandra and run some read heavy or write heavy operations.
-
Check the GC logs.
Note: This method decreases performance for the test node, but generally does not significantly reduce cluster performance.
If performance does not improve, contact the DataStax Services team for additional help.