Monday 25 September 2017

Lots of Old Gen GC in my JVM

Frequent Old Gen GC issues with JVM

Garbage collection in JVM is more about not moving short lived  objects to Old Gen and also not keeping long lived objects too long in Young Gen. So, as you can see there is always a compromise between the two.

Some known issues causing  high GC ::

1) Check you logger version. Some logger version do create a lot of logging objects even on INFO mode. Some are know to still create object of debug and trace level despite of a higher logging mode.
Choose an appropriate logger version which is not known to cause GC issues.

2) Choose the correct serialisation and deserialisation technique in you application. As an example, bytes should be directly deserialised to the required object and not to String and then the required objects.

3) Be careful in using string objects. Do not create too many strings and objects on every request. Keep strings/objects cached whenever possible. And use Singletons whenever possible.

How to tune GC ::

1) Try the new G1 garbage collector. This is the best default GC.

2) If there are too many old gen GC's, and if the old gen GC time is too long, then increasing the Young Gen size is required. Keep on increasing the Young Gen size to see the reduction in the frequency of Old Gen GC and their time.

3) If step1 does not work, then consider increasing the overall heap space(-Xmx) for your JVM. Be careful to leave enough free memory for the OS. Otherwise memory swaps can start to happen.
Increasing the max heap size and accomodating this increase in Young Gen is a known solution to decrease the number of old gens.


No comments:

Post a Comment