Mastering JDK8 GC: Practical Tuning Guide for High‑Performance Applications
This guide summarizes JD.com’s extensive JDK8 garbage‑collector optimization experience, covering version requirements, how to select the right GC, core and collector‑specific parameter settings, logging configuration, and concrete methods to assess GC health for latency‑sensitive and throughput‑oriented workloads.
1. JDK Version
All optimizations assume JDK 8, preferably update 191 or later; upgrading from older versions is strongly recommended.
2. Choosing a Garbage Collector
For latency‑sensitive C‑end applications with heap >8 GB, use G1; for smaller heaps or older JDKs, choose CMS. For throughput‑oriented workloads such as MQ or workers, ParallelGC is recommended.
3. Core Parameter Settings (Applicable to All Applications and Collectors)
-Xmx: typically 50 % of container memory -Xms: same as
-Xmx -XX:MetaspaceSize: 256 MB–512 MB -XX:ParallelGCThreads: equal to container CPU cores -XX:CICompilerCount: equal to container CPU cores (minimum 2)
4. Collector‑Specific Settings
ParallelGC (default in JDK 8)
No additional tuning beyond the core parameters is usually required.
CMS
-XX:+UseConcMarkSweepGC -Xmn: roughly one‑third of heap, required when -XX:ParallelGCThreads is set -XX:ConcGCThreads=n: default ParallelGCThreads/4, can be increased to
ParallelGCThreads/2 -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70(recommended)
G1
-XX:+UseG1GC -XX:ConcGCThreads=n: same rule as CMS -XX:G1HeapRegionSize=8m: set when heap ≤8 GB and many large objects exist
Do not set -Xmn or
-XX:NewRatio5. Additional Tuning Parameters
-XX:+ParallelRefProcEnabled: enable parallel reference processing when many WeakReference objects cause long GC pauses
6. Enabling GC Logging
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/export/Logs/gc.log7. How to Verify GC Health
Frequency: Young GC every few dozen seconds; Full GC a few times per day (G1 should avoid Full GC).
Duration: Young GC should take tens of milliseconds; Full GC a few hundred milliseconds, depending on heap size and object churn.
Memory trend: After startup, Young GC should reduce memory to a low watermark; over time the old generation grows until a Full/Mixed GC resets it. Lack of this pattern may indicate a leak.
For ParallelGC, Full GC occurs only when heap is exhausted, so no heap‑usage alerts are needed; monitor GC frequency instead.
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.
JD Retail Technology
Official platform of JD Retail Technology, delivering insightful R&D news and a deep look into the lives and work of technologists.
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.
