Analysis of JVM GC Configuration Guide | JD Cloud Technical Team

The purpose of this article is to briefly explain the tuning parameters of each collector. Please correct me if there are any omissions.

1. JDK version

All the following optimizations are based on the JDK8 version. It is strongly recommended to upgrade the lower version to JDK8, and use update_191 or later versions as much as possible.

2. How to choose a garbage collector

Response-first application: For C-side applications that are sensitive to response time, it is recommended to choose G1 if the heap memory is above 8G, and choose CMS if the heap memory is small or the version of JDK is low;

Throughput priority application: it is not sensitive to response time, and the application with high throughput as the goal (such as MQ, Worker), it is recommended to choose ParallelGC;

3. Optimize parameters of each collector

1) Basic parameter configuration (required for all applications and all collectors):

-Xmx (usually 50% of container memory)

-Xms (consistent with Xmx)

-XX: MetaspaceSize (usually 256M~512M)

-XX:ParallelGCThreads=Number of container cores

-XX:CICompilerCount=The number of container cores (must be greater than or equal to 2)

2)ParallelGC

In addition to the above parameters, generally no additional tuning is required (JDK8 default collector)

3)CMS

-XX:+UseConcMarkSweepGC

-Xmn (generally one-third of the heap memory), especially after configuring ParallelGCThreads must be configured

-XX:ConcGCThreads=n (the default is ParallelGCThreads/4, it can be adjusted to ParallelGCThreads/2 according to the situation)

-XX:+UseCMSInitiatingOccupancyOnly

-XX:CMSInitiatingOccupancyFraction=70 (recommended value)

4)G1

-XX:+UseG1GC

-XX:ConcGCThreads=n (the default is ParallelGCThreads/4, it can be adjusted to ParallelGCThreads/2 according to the situation)

-XX:G1HeapRegionSize=8m (if the heap memory is within 8G and there are many large objects, it is recommended to set this value)

*Be careful not to set -Xmn and XX:NewRatio

5) Other tuning parameters

-XX:+ParallelRefProcEnabled If the Reference processing time is long during GC, for example, a large number of WeakReference objects are used, parallel processing can be enabled through this parameter

4. Turn on the GC log

-XX:+PrintGCDetails

-XX:+PrintGCDateStamps

-Xloggc:/export/Logs/gc.log

5. How to judge whether the GC is normal

1) Whether the GC is frequent: the frequency of YoungGC is generally tens of seconds, and the frequency of FullGC is generally several times a day. Note that FullGC should not appear in the G1 recycler;

2) GC time consumption: The time consumption mainly depends on the size of the heap memory and the number of garbage objects. The YoungGC time should usually be tens of milliseconds, and the FullGC time should be hundreds of milliseconds;

3) Whether the GC memory drops every time: When the application is just started, the YoungGC memory should be recycled to a lower water level each time. As time goes by, the old generation will gradually increase, and the memory water level will gradually rise until FullGC/MixedGC (G1), the memory will be Go back to the lower water mark again, otherwise there may be a memory leak;

4) If ParallelGC is used, FullGC will be triggered only when the heap memory is exhausted, so there is no need to configure the heap memory usage alarm, but you need to pay attention to the GC frequency;

5) Part of the JVM configuration can be inspected on Taishan.

Author: Jingdong Retail Wang Lihui

Source: JD Cloud Developer Community

Guess you like

Origin blog.csdn.net/jdcdev_/article/details/131678341