Memory management with G1 Garbage Collector
Garbage collection (GC) is a form of automatic memory management. The garbage collector attempts to reclaim garbage or memory occupied by objects that are no longer in use by a system.
Overview
The Garbage-First (G1) Collector is a server-style garbage collector, targeted for multi-processor machines with large memories. It meets garbage collection (GC) pause time goals with a high probability while achieving high throughput. The G1 garbage collector is fully supported in Oracle JDK 7 update 4 and later releases.
The G1 collector is designed for applications that:
can operate concurrently with applications threads
have compact free space without lengthy GC induced pause times
need more predictable GC pause durations
do not want to sacrifice a lot of throughput performance
do not require a much larger Java heap
For more information, see Getting Started with the G1 Garbage Collector, by Oracle.
Prerequisites
Use Java version 1.8.0_latest for systems prior to censhare 2019.2.
Recommended use cases of G1
The focus of G1 is to provide a solution for users running applications that require large heaps with limited GC latency. This means heap sizes of around 6 GB or larger, and stable and predictable pause time below 0.5 seconds.
Full GC durations are too long or too frequent.
The rate of object allocation or promotion varies significantly.
Undesired long garbage collection or compaction pauses (longer than 0.5 to 1 second)
Basic command line
-XX:+UseG1GC
Tells the JVM to use the G1 Garbage collector.-XX:G1HeapRegionSize=16m
Defines larger HeapRegionSize to cope with so-called humungous objects, which may occur because of the way the censhare CDB stores large arrays.-XX:MaxGCPauseMillis=500
Sets a target for the maximum GC pause time. This is a soft goal, and the JVM will make its best effort to achieve it. Therefore, the pause time goal is sometimes not met. The default value is 200 milliseconds, for censhare we recommend 500 ms.-XX:InitiatingHeapOccupancyPercent=45
Percentage of the (entire) heap occupancy to start a concurrent GC cycle. It is used by G1 to trigger a concurrent GC cycle based on the occupancy of the entire heap, not just one of the generations. A value of 0 denotes 'do constant GC cycles'. The default value is 45 (i.e., 45% full or occupied).
These parameters can be added in ~/cscs/app/config/launcher.xml in order to enable G1 on the censhare Server.
Starting from Oracle JDK Version 9, G1 GC is the default Garbage Collector. Therefore we added a commented setting for G1 GC to censhare version 2019.2.0. This server version requires JDK 11.
GC1 log analysis
Graphical visualization & insightful metrics of G1 GC logs can be analyzed with a GC log analysis tool, for example http://gceasy.io/.
Disabled or remove the below parameters from the launcher.xml:
<jvmarg value="-XX:NewSize=1G" enabled="true"/>
<jvmarg value="-XX:MaxNewSize=1G" enabled="true"/>
<jvmarg value="-XX:+UseParallelGC"/>
<jvmarg value="-XX:+UseParallelOldGC"/>
<jvmarg value="-XX:ParallelGCThreads=7" />
<jvmarg value="-XX:SurvivorRatio=16" />
<jvmarg value="-XX:TargetSurvivorRatio=50" />
<jvmarg value="-XX:MaxTenuringThreshold=15" />
Add the below parameters to the launcher.xml:
<jvmarg value="-XX:+UseCompressedOops" enabled="true"/>
<jvmarg value="-XX:+UseG1GC"/>
<jvmarg value="-XX:G1HeapRegionSize=16m"/>
<jvmarg value="-XX:MaxGCPauseMillis=500"/>