Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java old generation keeps growing until Tomcat restarts

I have JDK 8 on multiple servers and the heap size keeps increasing till it reaches 90% and the application fails. During this time period multiple GCs run but the old generation keeps growing until the application fails. The current work around is to restart Tomcat. My server has 15GB RAM, 4 core CPU. My Java setup is:

-Xms12036M -Xmx12036M -Xmn800M 

Is there any recommendation on these values? I thought the GC would take care of it, but the old generation but appears not to be. I am new to Java and not sure if this indicates a memory leak or if the GC is not doing such thing?

like image 421
raindrop Avatar asked Mar 25 '26 16:03

raindrop


1 Answers

First check on memory leak front with JStacks/JMaps, thread dumps and Memory analyser tools. If you don't have any leaks in memory of your system, you have to fine tune garbage collector algorithms.

Java offers different types of garbage collectors.

Have a look at strengths & weakness of various GC algorithms

  1. The Serial Collector: The serial collector is the simplest one, and the one you probably won’t be using, as it’s mainly designed for single-threaded environments.

  2. The Parallel / Throughput collector: Its biggest advantage is that is uses multiple threads to scan through and compact the heap. The downside to the parallel collector is that it will stop application threads when performing either a minor or full GC collection.

  3. The CMS Collector: This algorithm uses multiple threads (“concurrent”) to scan through the heap (“mark”) for unused objects that can be recycled (“sweep”). It will be efficient if you either increase the size of the old generation (or the entire heap for that matter) or allocate more background threads to the collector.It uses more CPU in order to provide the application with higher levels of continuous throughput.

  4. The G1 Collector: The Garbage first collector (G1) introduced in JDK 7 update 4 was designed to better support heaps larger than 4GB. The G1 collector utilizes multiple background threads to scan through the heap that it divides into regions, spanning from 1MB to 32MB (depending on the size of your heap). using the –XX:+UseG1GC flag.

If you are using G1 collector, you have to fine tune region size parameter. If 15 GB is your heap size, your region size should be (15 GB / 2048 ) MB, which is around 7 MB. Do not experiment more on New Gen Size. You can stick to default settings since this algorithm provides best performance with default values.

Have a look at this article:

https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/g1_gc_tuning.html

like image 60
Ravindra babu Avatar answered Mar 27 '26 05:03

Ravindra babu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!