Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

11/4/2020

Reading time:3 min

Changing heap size parameters

by John Doe

Adjust the minimum, maximum and new generation heap sizes to tune JVM.By default, DataStax Distribution of Apache Cassandra™ (DDAC) sets the Java Virtual Machine (JVM) heap size from 1 to 32 GB depending on the amount of RAM and type of Java installed. Theautomatically 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 thefile:Minimum (-Xms) Maximum (-Xmx) New generation (-Xmn) Parallel processing for GC (-XX:+UseParallelGC) Restriction: When overriding the default setting, both min and max must be defined the 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 recommendationsSetting 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.For production use, follow these guidelines to adjust heap size for your environment: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. Note: For more tuning tips, see Secret HotSpot option improving GC pauses on large heaps.Maximum and minimum heap sizeThe recommended maximum heap size depends on which GC is used:G1 for newer computers (8+ cores) with up to 256 GB RAM 16 GB to 32 GBSee Java performance tuning. CMS for newer computers (8+ cores) with up to 256 GB RAM No more than 16 GB Older computers Typically 8 GB New heap sizeFor CMS, you may 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:100 times the number of cores ¼ of MAX_HEAP_SIZE Procedure To enable GC logging, uncomment the loggc parameter in the 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 file: 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 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 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 Save and close the jvm.options file. Restart Cassandra and run some read heavy or write heavy operations. Check the GC logs.

Illustration Image

Adjust the minimum, maximum and new generation heap sizes to tune JVM.

By default, DataStax Distribution of Apache Cassandra™ (DDAC) sets the Java Virtual Machine (JVM) heap size from 1 to 32 GB depending on the amount of RAM and type of Java installed. Theautomatically 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 thefile:
  • Minimum (-Xms)
  • Maximum (-Xmx)
  • New generation (-Xmn)
  • Parallel processing for GC (-XX:+UseParallelGC)

Restriction: When overriding the default setting, both min and max must be defined the 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

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.

For production use, follow these guidelines to adjust heap size for your environment:
  • 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.

Note: For more tuning tips, see Secret HotSpot option improving GC pauses on large heaps.

Maximum and minimum heap size

The recommended maximum heap size depends on which GC is used:
G1 for newer computers (8+ cores) with up to 256 GB RAM 16 GB to 32 GB

See Java performance tuning.

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

For CMS, you may 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:
  • 100 times the number of cores
  • ¼ of MAX_HEAP_SIZE

Procedure

  1. To enable GC logging, uncomment the loggc parameter in the file.
    -Xloggc:/var/log/cassandra/gc.log

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

  2. Set the heap sizes in the 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
    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
  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
  4. Save and close the jvm.options file.
  5. Restart Cassandra and run some read heavy or write heavy operations.
  6. Check the GC logs.

Related Articles

spring
rest
api

GitHub - DataStax-Examples/spring-data-starter: ⚡️ A sample Spring Data Cassandra REST API

John Doe

2/14/2024

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

cassandra