Changing heap size parameters

By default, DataStax Enterprise (DSE) sets the Java Virtual Machine (JVM) heap size from 1 to 32 GB depending on the amount of RAM and type of Java installed. The cassandra-env.sh automatically configures the min and max size to the same value using the following formula:

max(min(1/2 ram, 1024 megabytes), min(1/4 ram, 32765 megabytes))

To adjust the JVM heap size, uncomment and set the following parameters in the jvm-server.options file:

  • Minimum (-Xms)

  • Maximum (-Xmx)

  • New generation (-Xmn)

  • Parallel processing for GC (-XX:+UseParNewGC) located in jvm8-server.options or jvm11-server.options depending upon the JDK.

Restriction: When overriding the default setting, both min and max must be defined the jvm-server.options file.

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.

Guidelines and recommendations

For production use, follow these guidelines to adjust heap size for your environment:

  • Heap size is usually between one quarter (25 percent) and one half (50 percent) of system memory, but no larger than 32 GB.

  • Setting the Java heap higher than 32 GB can interfere with the OS page cache. Operating systems that maintain the OS page cache for frequently accessed data are good at keeping this data in memory. Properly tuning the OS page cache usually results in better performance than increasing the row cache.

  • 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.

  • Enable parallel processing for GC, particularly when using DSE Search.

  • 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 or lowering cache sizes.

  • The DataStax recommendations for maximum heap size (MAX_HEAP_SIZE) depends on which GC is used:

    • A node using G1: Set MAX_HEAP_SIZE as large as possible, up to 64 GB.

    • G1 for newer machines (8 or more cores) with up to 256 GB RAM: Set MAX_HEAP_SIZE between 16 GB and 32 GB. See Java performance tuning.

    • CMS for newer machines (8 or more cores) with up to 256 GB RAM: Set MAX_HEAP_SIZE to no more than 16 GB.

    • Older machines: MAX_HEAP_SIZE is typically set to 8 GB.

  • For CMS, you might also need to adjust new (young) generation heap size. This setting determines the amount of heap memory allocated to newer objects. The database calculates the default value for this property in megabytes (MB) as the lesser of the following:

    • 100 times the number of cores

    • One quarter (25 percent) of MAX_HEAP_SIZE

Procedure

  1. To enable GC logging, uncomment the loggc parameter located in jvm8-server.options or jvm11-server.options depending upon the JDK.

    -Xloggc:/var/log/cassandra/gc.log

    After restarting Apache Cassandra the log is created and GC events are recorded.

  2. Set the heap sizes in the jvm-server.options file:

    1. Uncomment and set both the min and max heap size. For example to set both the min and max heap size to 16 GB:

      -Xms16G
      -Xmx16G

      Set the min (-Xms) and max (-Xmx) heap sizes to the same value to avoid stop-the-world GC pauses during resize, and to lock the heap in memory on startup which prevents any of it from being swapped out.

    2. If using CMS, uncomment and set the new generation heap size to tune the heap for CMS. As a starting point, set the new parameter to 100 MB per physical CPU core. For example, for a modern eight-core or greater system:

      -Xmn800M

      A larger size leads to longer GC pause times. For a smaller new size, GC pauses are shorter but usually more expensive.

  3. 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.

    Alternatively, you can set an environment variable called MAX_DIRECT_MEM, instead of setting a size for -XX:MaxDirectMemorySize in the jvm-server.options file.

  4. Save and close the jvm-server.options file.

  5. Restart Apache Cassandra and run some read heavy or write heavy operations.

  6. Check the GC logs.

    This method decreases performance for the test node, but generally does not significantly reduce cluster performance.

    If performance does not improve, contact DataStax Support for additional help.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2025 | Privacy policy | Terms of use Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM