JVM learning (3) Common tuning parameters

Heap size setting

Example analysis 1

java -Xmx3550m -Xms3550m -Xmn2g -Xss128k

-Xms (set the initial java heap size) -Xmx (set the maximum java heap memory size) -Xss (the stack size occupied by a single thread) -Xmn (the size of the young generation)

  1. -Xms and -Xmx have the same value, then the initialization is to limit the maximum memory size of java
  2. We set the maximum size here and the size of the young generation, then the remaining memory size will definitely have an impact on old age

Example analysis 2

-XX:NewRatio=4 -XX:SurvivorRatio=4 -XX:MaxPermSize=16m -XX:MaxTenuringThreshold=0

-XX: NewRatio = 4: Set the size ratio of Eden area and Survivor area in the young generation. Set to 4, the ratio of two Survivor districts to one Eden district is 2: 4, one Survivor district accounts for 1/6 of the entire young generation -XX: MaxPermSize = 16m: setting (including Eden and two Survivor districts) and year The ratio of the old generation (excluding the permanent generation). Set to 4, the ratio of the young generation to the old generation is 1: 4, and the young generation accounts for 1/5 of the entire stack -XX: SurvivorRatio = 4: Set the size of the persistent generation to 16m. -XX: MaxTenuringThreshold sets the number of generations after recycling to the old generation

The choice of recycler

The JVM gives three choices: serial collector, parallel collector, and concurrent collector, but the serial collector is only suitable for small amounts of data, so the choices here are mainly for parallel collectors and concurrent collectors. By default, JDK5.0 used serial collectors before. If you want to use other collectors, you need to add the corresponding parameters at startup. After JDK5.0, JVM will judge according to the current system configuration.

Throughput-first parallel collector

Example analysis 1

java -Xmx3800m -Xms3800m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:ParallelGCThreads=20

-XX: + UseParallelGC: select the garbage collector as the parallel collector. This configuration is only valid for the young generation. In the above configuration, the young generation uses concurrent collection, while the old generation still uses serial collection. -XX: ParallelGCThreads = 20: configure the number of threads of the parallel collector, that is: how many threads are simultaneously garbage collected. This value is best configured equal to the number of processors.

Example analysis 2

java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:ParallelGCThreads=20 -XX:+UseParallelOldGC

-XX: + UseParallelOldGC: Configure the old generation garbage collection method as parallel collection. JDK6.0 supports parallel collection of old and old generations.

Example analysis 3

java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseParallelGC  -XX:MaxGCPauseMillis=100 -XX:+UseAdaptiveSizePolicy

-XX: + UseAdaptiveSizePolicy: After setting this option, the parallel collector will automatically select the size of the young generation area and the corresponding Survivor area ratio to achieve the minimum corresponding time or collection frequency specified by the target system. This value is recommended when using a parallel collector , Always open.

Concurrent collector with priority on response time

Example analysis 1

java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:ParallelGCThreads=20 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC

-XX: + UseConcMarkSweepGC: Set the old generation for concurrent collection.

Example analysis 2

java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseConcMarkSweepGC -XX:CMSFullGCsBeforeCompaction=5 -XX:+UseCMSCompactAtFullCollection

-XX: CMSFullGCsBeforeCompaction: Because the concurrent collector does not compress or organize the memory space, "fragmentation" will occur after a period of time, which reduces the efficiency of operation. This value sets how many times the GC runs to compress and organize the memory space. -XX: + UseCMSCompactAtFullCollection: Turn on the compression of the old generation. May affect performance, but can eliminate fragmentation

Supplementary information

-XX: + PrintGC: print GC 

 -XX: + PrintGCDetails: more detailed information 

 -XX: + PrintGCApplicationStoppedTime: the time the program was paused during print garbage collection. 

 -Xloggc: filename: Used in conjunction with the above to record related log information to a file for analysis.

For example, a usage example:

[root@xx jvm测试]# java -XX:+PrintGCDetails -Xloggc:jvmLog.txt DynamicDispatch 
man say hello
woman say hello
woman say hello

[root@xx jvm测试]# ls
'DynamicDispatch$Human.class'  'DynamicDispatch$Woman.class'   DynamicDispatch.java   hs_err_pid14941.log   StaticResolution.class
'DynamicDispatch$Man.class'     DynamicDispatch.class          hello.jar              jvmLog.txt            StaticResolution.java

[root@xx jvm测试]# vim jvmLog.txt 

supplement

How to analyze GC logs

Young GC logs: 1297993-20200415144935978-1256825494.png

Full GC log:

1297993-20200415144953890-141586730.png

Tuning summary

The parameters of jvm tuning are mainly from the following aspects:

  • Heap setting adjustment
  • Selection of serial parallel collector

References

  • https://www.iteye.com/blog/unixboy-174173 (must see)
  • https://www.one-tab.com/page/l6WE1xp_TDyEN5iQNVyOEA

Guess you like

Origin www.cnblogs.com/Benjious/p/12705275.html