javagarbage-collectionjvmg1gc

When not to use G1GC garbage collector?


I looked into differences between various garbage collectors available for JVM. Here is the answer explaining the main differences between them : https://stackoverflow.com/a/54619838/5345646

Here it's said for G1GC that :

It's low pause / server style gc, mainly for large heap (> 4Gb).

We have a machine that has a total memory of 4 GB, and heap size allocated to JVM of 1 GB. I wanted to understand whether that would cause any issues for us, or would G1GC work out fine.


Solution

  • The following summary is based on:


    The old CMS collector has been removed as of Java 14.


    Note that if you specify pause-time and/or throughput goals, you can leave the choice and tuning of the GC to the JVM. This is probably less risky than manually selecting and tuning the GC ... when you don't understand what you are doing.

    This "behavior-based tuning" approach and its advantages are described here.


    You asked:

    We have a machine that has a total memory of 4 GB, and heap size allocated to JVM of 1 GB. I wanted to understand whether that would cause any issues for us, or would G1GC work out fine.

    We can't tell you whether it would work out fine or not. It would depend on various aspects of your application's behavior and also on your expectations. For example, what "issues" would concern you if your application encountered them. I would recommend trying "behavior-based tuning" to start with, and see where that gets you.

    Finally, setting a maximum heap size that is too small for the application will not end well ... no matter what GC you select.