当前位置:网站首页>How to monitor JVM GC

How to monitor JVM GC

2022-06-09 05:43:00 Die hard audio and video

How to monitor GC

gc Monitoring is GC Necessary prerequisites for tuning , Only monitoring data , To know whether or not GC tuning ? How to tune ? Is tuning effective ?

There are many ways to monitor GC, The difference is only the form of presentation , So you don't have to learn all the monitoring gc Methods .

jstat

jstat yes HotSpot JVM Provides a monitoring tool ,jstat Not only provide GC Operational information , It also provides information about class loading operations and runtime compiler operations .

jstat Be placed in $JDK_HOME/bin. So long as java and javac Can execute ,jstat The same can be done .
You can execute the following statements in a command line environment .

jps Acquisition process id

jps
jstat -gc 28352 1000

S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT
122048.0 124224.0  0.0   1945.4 1452288.0 537235.5  490368.0   163970.8    -      -      -      -        33    1.843   2      0.697    2.541
122048.0 124224.0  0.0   1945.4 1452288.0 537235.5  490368.0   163970.8    -      -      -      -        33    1.843   2      0.697    2.541
122048.0 124224.0  0.0   1945.4 1452288.0 537235.5  490368.0   163970.8    -      -      -      -        33    1.843   2      0.697    2.541
122048.0 124224.0  0.0   1945.4 1452288.0 537235.5  490368.0   163970.8    -      -      -      -        33    1.843   2      0.697    2.541
122048.0 124224.0  0.0   1945.4 1452288.0 537235.5  490368.0   163970.8    -      -      -      -        33    1.843   2      0.697    2.541

Want to get GC Performance related data needs to be continuously monitored , So in execution jstat when , Output regularly GC Monitoring information .

perform jstat –gc 1000 ( or 1s) Will show every second GC Monitoring data .jstat –gc 1000 10 Every time 1 Every second , And altogether 10 Time .

have access to jstat -options To see other options , Different jdk Versions may vary .

Options describe
gc Shows the current size of each heap area and its current usage (Ede、survivor、old etc. )、 Executive GC Total and GC Cumulative time of operation
gccapactiy Shows the minimum size of each heap area (ms) And maximum size (mx)、 Current size and execution of each region GC frequency .( No display GC Current usage and cumulative time of the operation
gccause It shows -gcutil Information provided The last time GC The reason and current GC Why .
gcnew Show the space of the younger generation GC The performance data
gcnewcapacity Show statistics on the size of the younger generation space
gcold The output of the elderly generation space GC The performance data
gcoldcapacity Output the size statistics of the older generation space
gcpermcapacity Output the size statistics of the permanent generation space
gcutil Output the usage percentage of each heap area , as well as gc Total number of executions and GC Cumulative time of operation

The most used command ,gcutil,gc,gccapacity

  • gcutil Used to check the usage of the heap area 、 Executive GC Times and GC Total cumulative time of operation
  • gccapacity Option and other options can be used to check the actual size of the allocation .
  • gc Used to view the current in real time gc situation

Output column information

 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here

summary :jstat The benefits of , You can use it as long as you have a console .

When using –gcutil Will output the following information . stay GC When optimizing , You need to pay special attention to YGC, YGCT, FGC, FGCT and GCT.

S0      S1       E        O        P        YGC    YGCT     FGC    FGCT     GCT
0.00    66.44    54.12    10.58    86.63    217    0.928     2     0.067    0.995
0.00    66.44    54.12    10.58    86.63    217    0.928     2     0.067    0.995
0.00    66.44    54.12    10.58    86.63    217    0.928     2     0.067    0.995

In this case ,YGC( The younger generation gc The total number of times ) yes 217 and YGCT( The younger generation gc Total time ) yes 0.928, So after simply averaging the data (0.928/217=0.004 second ), You can see that every new generation GC Probably need 4ms(0.004 second ), and full GC The average time of is 33ms.

But that doesn't tell the story , The average data cannot be analyzed to determine each time gc Time spent , such as full gc Total time 70ms, altogether gc two , One of them was 10ms, And the other might be 60ms, So in order to be more accurate gc problem , have access to -verbosegc.

-verbosegc

-verbosegc It's starting a Java Can be specified when applying JVM Parameters ,jstat You can do this without specifying any jvm Parameter .
 Insert picture description here

Here is -verbosegc The available parameters of

  • -XX:+PrintGCDetails
  • -XX:+PrintGCTimeStamps
  • -XX:+PrintHeapAtGC
  • -XX:+PrintGCDateStamps (from JDK 6 update 4)

jdk1.6 Example

java -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:./gc.log -jar test.jar

YoungGC The log is explained as follows :

YoungGC The log is explained as follows :

FullGC The log is explained as follows

 Insert picture description here

springboot actuator Report points + prometheus collect + grafana Graphic display

1. be based on springboot Business reporting points gradle To configure :

compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'io.micrometer:micrometer-registry-prometheus'

2. To configure yml

management:  
    endpoints:      
        web:        
            exposure:          
                include: health,prometheus          

 Default point reporting url:
http://ip:port/actuator/prometheus

3. install promethues
4. install grafana, Import Spring Boot 2.1 Statistics Templates

Memory leak - Young generation eden Characteristics of the zone :

!4

Memory leak - Characteristics of old age :

 Insert picture description here

Memory leak - Young generation survivor Characteristics of the zone :

 Insert picture description here

Memory leak -gc Stop The World diagram :

 Insert picture description here

summary

In general use jstat To monitor gc, If you feel gc There is a problem , have access to verbosegc Parameters . If you use springboot, have access to springboot actuator Report points + prometheus collect + grafana Graphic display programme .

原网站

版权声明
本文为[Die hard audio and video]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203021427409179.html