Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 877
user1870400 Avatar asked Jan 12 '16 13:01

user1870400


People also ask

How do I set maximum heap size?

Under the Java tab, select JVM Options. Edit the -Xmx256m option. This option sets the JVM heap size. Set the -Xmx256m option to a higher value, such as Xmx1024m.

What is the maximum recommended JVM heap size?

The theoretical limit is 2^64 bytes, which is 16 exabytes (1 exabyte = 1024 petabytes, 1 petabyte = 1024 terabytes). However, most OS's can't handle that. For instance, Linux can only support 64 terabytes of data. Note: We don't recommend you exceed 2 GB of in use JVM heap.


2 Answers

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.

like image 119
Aaron Avatar answered Sep 18 '22 01:09

Aaron


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

like image 42
Ty Hitzeman Avatar answered Sep 20 '22 01:09

Ty Hitzeman