JVMTuning is mainly aimed at tuning memory management, including controlling the size of each generation, GC policy. Because the GC starts garbage collection when hanging application threads, seriously affecting performance, the purpose of tuning is to minimize the GC caused by the application thread pause time, reduce the number of Full GC.
Generation size tuning
Key parameters: – Xms, Xmx, – Xmn, – XX: Survivor Ratio, – XX: MaxTenuring Threshold, – XX: PermSize, – XX: MaxPermSize
-Xms、 -Xmx Usually set to the same value, avoiding constantly expanding JVM memory at runtime, this value determines the maximum memory that the JVM heap can use.
-Xmn Determining the size of Cenozoic space, the ratio of Cenozoic Eden, S0, and S1 can be controlled by – XX: Survivor Ratio (if the value is 4: Eden: S0: S1 = 4:3)
-XX:MaxTenuringThreshold The control object passes through the minor GC several times before entering the old age, and this parameter is valid only when the serial GC is in effect.
-XX:PermSize、-XX:MaxPermSize The size used to control the method area is usually set to the same value.
1.Avoid the small size of the new generation.
When the Cenozoic set too small, there are two obvious phenomena, one is the frequent number of minor GC, and the other may lead to minor GC objects directly into the elderly. When old age memory is insufficient, it will trigger Full GC.
2.Avoid setting up new generation.
Over-setting of the Cenozoic will bring about two problems: one is that the elderly become smaller, which may lead to frequent implementation of Full GC; the other is that the implementation of recycling time of minor GC has greatly increased.
3.Avoid too large or too small Survivor area.
-XX:SurvivorRatioThe larger the value of the parameter, the larger the Eden region, the lower the number of minor GC, but the smaller the two Survivor regions. If objects larger than the memory size of the Survivor region are not recovered after minor GC, they will go directly into the old age.
-XX:SurvivorRatioSmall parameter values mean smaller Eden regions, more minor GC triggers, larger Survivor regions, and more objects that survive minor GC to avoid aging.
4.Reasonably set the survival period of objects in the new generation
The value of the Cenozoic survival cycle determines how many times the new generation of Minor GC enters the old generation. So this value should be tuned for your application. The value on the Jvm parameter corresponds to – XX: MaxTenuringThreshold, defaulting to 15 times.
GCtuning
1.GCcollocation
See another garbage collector.
2.View JVM parameters
Command line tool visualization tool
3.GCLog parameters
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-Xloggc:c:\java\gc.log