How to set Cassandra (>2.0) JVM heap size of 8GB?
Asked Answered
P

2

6

How to set Cassandra (>2.0) JVM heap size of 8GB? When I type in free -m it gives me the following. How can I set the Cassandra JVM heap size to 8GB?

             total       used       free     shared    buffers     cached
Mem:         16047      11336       4711          0         81       5814
-/+ buffers/cache:       5441      10606
Swap:            0          0          0
Perren answered 12/1, 2016 at 13:47 Comment(0)
M
7

As stated in the Tuning Java resources section of the documentation:

If you decide to change the Java heap sizing, both MAX_HEAP_SIZE and HEAP_NEWSIZE should should be set together in conf/cassandra-env.sh.

Inside cassandra-env.sh, search for this line:

#MAX_HEAP_SIZE="4G"

That line in the code happens after the MAX_HEAP_SIZE calculations have happened, so it works as an override. Uncomment it, and set it accordingly.

MAX_HEAP_SIZE="8G"

Be careful going above 8G. For guidance on tuning the JVM, I recommend Amy Tobey's Cassandra 2.1 Tuning Guide. She offers some tips for tuning CMS, as well as a great section on implementing the new G1GC.

Mamba answered 12/1, 2016 at 14:16 Comment(2)
what should HEAP_NEWSIZE be set to? from your responsePerren
The old way was to set 100mb per CPU core, now (for CMS) the usual advice is to start with around 25% of your MAX_HEAP_SIZE.Mamba
O
3

Update cassandra-env.sh

remove / comment out the entire calculate_heap_sizes() function

  • this is the function that is called by cassandra to automatically allocate JVM size.
  • it takes the lower of 1/4 system memory or 8GB. This is why the default max JVM size is 8GB

Remove/comment out other line with $MAX_HEAP_SIZE.

  • The line starts with: "only calcuate the size if..."

  • delete / keep HEAP_NEWSIZE commented out

set MAX_HEAP_SIZE to the new value. Ex: 16G

  • this should be the only place you need to do this

Restart

  • Ideally, you'd only need to restart the Cassandra service. However, I've only gotten it to work after restarting the entire machine.

Also see for another example: https://medium.com/@mlowicki/move-cassandra-2-1-to-g1-garbage-collector-b9fb27365509

Occam answered 5/6, 2018 at 15:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.