Practical Guide to Tuning the G1 Garbage Collector in Java
This article shares practical experience tuning Java's G1GC, including required JVM flags, key parameters such as G1NewSizePercent and InitiatingHeapOccupancyPercent, an automated script for systematic parameter adjustment, and tools for log analysis to achieve optimal garbage‑collection performance.
Readers interested in joining the HBase discussion group can contact the author directly.
Xiaomi has started large‑scale use of the G1 garbage‑collection algorithm, and the author intends to document tuning experiences for G1GC.
A previously shared PPT on G1GC tuning is available at http://openinx.github.io/2012/01/01/my-share/ . For newcomers, the Oracle G1 tutorial and the original "Garbage‑First Garbage Collection" paper are recommended.
To collect detailed G1GC logs, enable the following JVM options:
-Xmx30g -Xms30g
-XX:MaxDirectMemorySize=30g
-XX:+UseG1GC
-XX:+UnlockExperimentalVMOptions
-XX:MaxGCPauseMillis=90
-XX:G1NewSizePercent=8
-XX:InitiatingHeapOccupancyPercent=30
-XX:+ParallelRefProcEnabled
-XX:ConcGCThreads=4
-XX:ParallelGCThreads=16
-XX:MaxTenuringThreshold=1
-XX:G1HeapRegionSize=32m
-XX:G1MixedGCCountTarget=64
-XX:G1OldCSetRegionThresholdPercent=5Key parameters to tune include:
G1NewSizePercent : minimum percentage of the Young generation; adjust based on Young GC pause times.
InitiatingHeapOccupancyPercent : threshold at which G1 starts mixed GCs to compact the old generation.
G1MixedGCCountTarget : maximum number of mixed GCs to run after the occupancy threshold is exceeded.
MaxTenuringThreshold : number of young‑generation collections after which an object is promoted to the old generation.
G1HeapRegionSize : size of each G1 region (e.g., 32m).
Because each parameter has a wide range, the author created a Python script ( java-g1gc-tuning.py ) that iteratively modifies a single parameter, restarts the cluster, runs a one‑hour performance test, and records start/end timestamps. After testing all parameters, log analysis is performed using HubSpot’s gc_log_visualizer tool, which extracts data via regex and generates monitoring charts.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Big Data Technology & Architecture
Wang Zhiwu, a big data expert, dedicated to sharing big data technology.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
