JVM tips – The G1 Garbage Collector
An old wisdom says that Software can be optimized for latency, throughput or footprint. The same is true for the JVM and its Garbage Collector(s).
Roughly speaking, the classic GC implementations each optimize for one aspect: Serial GC optimizes footprint, Parallel GC optimizes throughput and Concurrent Mark and Sweep (CMS) optimizes for response times and minimal GC induced latency.
But since JDK7u4, we officially have the “Garbage First” (G1) GC. It is still new enough to not even have its own Wikipedia article, but there are good introductory tutorials, articles and tuning guides.
In several ways, G1 is a step up from the conventional GC approaches: It uses non-contiguous heap regions instead of contiguous young and old generations and does most of its reclamation through copying of the live data, thus achieving compaction.
It is based on the principle of collecting the most garbage first and designed with scalability in mind, without compromising throughput.
The benefits of G1 have lead to a proposal and lively debate about Defaulting to G1 Garbage Collector in Java 9.
In conclusion, you can either take the easy path and use the default JVM settings or take some time to learn about modern GC choices and tuning options.
And if you get it all right you might be rewarded with your Java based services performing better than ever before … :)