2021-12-18 java性能分析

介绍一些jvm命令, 用来分析性能

  1. jps
    查看目前jvm有哪些进程,得到进程id
root@hulk-5c7d968dcd-dxkx9:/# jps
1 war
13518 Jps

想这个进程id为1的就是当前的项目进程

  1. jstat -gc pid
    查看gc情况
root@hulk-5c7d968dcd-dxkx9:/# jstat -gc 1
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
34944.0 34944.0  0.0   1941.7 279616.0 279384.9  699072.0   100063.8  107136.0 100602.0 12416.0 11314.7    967   20.738   4      1.011   21.749

每隔1000ms打印一次, 一共打印10次

root@hulk-5c7d968dcd-dxkx9:/# jstat -gc 1 1000 10
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
34944.0 34944.0 2587.6  0.0   279616.0  8109.1   699072.0   100134.6  107136.0 100602.0 12416.0 11314.7    968   20.747   4      1.011   21.758
34944.0 34944.0 2587.6  0.0   279616.0  8443.1   699072.0   100134.6  107136.0 100602.0 12416.0 11314.7    968   20.747   4      1.011   21.758
34944.0 34944.0 2587.6  0.0   279616.0  8496.8   699072.0   100134.6  107136.0 100602.0 12416.0 11314.7    968   20.747   4      1.011   21.758
34944.0 34944.0 2587.6  0.0   279616.0  8496.8   699072.0   100134.6  107136.0 100602.0 12416.0 11314.7    968   20.747   4      1.011   21.758
34944.0 34944.0 2587.6  0.0   279616.0  8545.5   699072.0   100134.6  107136.0 100602.0 12416.0 11314.7    968   20.747   4      1.011   21.758
34944.0 34944.0 2587.6  0.0   279616.0  8565.5   699072.0   100134.6  107136.0 100602.0 12416.0 11314.7    968   20.747   4      1.011   21.758

  1. jstack
    查看线程
root@hulk-5c7d968dcd-dxkx9:/# top -Hp 1
top - 08:06:23 up 1113 days,  2:43,  0 users,  load average: 2.33, 2.03, 2.01
Threads:  55 total,   0 running,  55 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  3.4 sy,  0.0 ni, 96.6 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  15886.7 total,    566.7 free,   8520.5 used,   6799.6 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.   7031.6 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                                                                                                                                         
    1 root      20   0 3619560 871440  14672 S   0.0   5.4   0:00.00 java                                                                                                                                                                            
    5 root      20   0 3619560 871440  14672 S   0.0   5.4   0:21.68 java                                                                                                                                                                            
    6 root      20   0 3619560 871440  14672 S   0.0   5.4   0:19.69 VM Thread                                                                                                                                                                       
    7 root      20   0 3619560 871440  14672 S   0.0   5.4   0:00.08 Reference Handl                                                                                                                                                                 
    8 root      20   0 3619560 871440  14672 S   0.0   5.4   0:00.36 Finalizer                                                                                                                                                                       
    9 root      20   0 3619560 871440  14672 S   0.0   5.4   0:00.00 Signal Dispatch                                                                                                                                                                 
   10 root      20   0 3619560 871440  14672 S   0.0   5.4   3:49.42 C2 CompilerThre                                                                                                                                                                 
   11 root      20   0 3619560 871440  14672 S   0.0   5.4   0:35.26 C1 CompilerThre                                                                                                                                                                 
   12 root      20   0 3619560 871440  14672 S   0.0   5.4   0:00.00 Service Thread                                                                                                                                                                  
   13 root      20   0 3619560 871440  14672 S   0.0   5.4   0:53.67 VM Periodic Tas                                                                                                                                                                 
   18 root      20   0 3619560 871440  14672 S   0.0   5.4   0:00.00 XNIO-1 I/O-1          

根据TIME+这一列得出哪个线程耗时最长
用命令查看该线程的十六进制值

root@hulk-5c7d968dcd-dxkx9:/# printf "%x\n" 40
28

查看是哪个类耗时的

root@hulk-5c7d968dcd-dxkx9:/# jstack 1 | grep 28
    - parking to wait for  <0x00000000d8bb6528> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
"XNIO-2 task-2" #37 prio=5 os_prio=0 tid=0x00007f84f4029800 nid=0x28 waiting on condition [0x00007f84f0734000]
    - parking to wait for  <0x00000000d6e228c0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
"DestroyJavaVM" #32 prio=5 os_prio=0 tid=0x00007f852800a800 nid=0x5 waiting on condition [0x0000000000000000]
"XNIO-2 Accept" #30 prio=5 os_prio=0 tid=0x00007f85289d4000 nid=0x23 runnable [0x00007f84f1039000]
"XNIO-2 I/O-2" #29 prio=5 os_prio=0 tid=0x00007f85289d3800 nid=0x22 runnable [0x00007f84f113a000]
"XNIO-2 I/O-1" #28 prio=5 os_prio=0 tid=0x00007f8529ffd800 nid=0x21 runnable [0x00007f84f123b000]
"spring.cloud.inetutils" #22 daemon prio=5 os_prio=0 tid=0x00007f852895e800 nid=0x1b waiting on condition [0x00007f84f1a41000]
"AsyncAppender-Worker-ASYNC_LOGSTASH" #21 daemon prio=5 os_prio=0 tid=0x00007f8528d6f000 nid=0x1a waiting on condition [0x00007f84f2e45000]
"Service Thread" #7 daemon prio=9 os_prio=0 tid=0x00007f85280e2000 nid=0xc runnable [0x0000000000000000]
"C1 CompilerThread1" #6 daemon prio=9 os_prio=0 tid=0x00007f85280dd000 nid=0xb waiting on condition [0x0000000000000000]
"C2 CompilerThread0" #5 daemon prio=9 os_prio=0 tid=0x00007f85280db800 nid=0xa waiting on condition [0x0000000000000000]
"Signal Dispatcher" #4 daemon prio=9 os_prio=0 tid=0x00007f85280c7000 nid=0x9 runnable [0x0000000000000000]
"Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007f85280a4000 nid=0x8 in Object.wait() [0x00007f852cd52000]
"Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007f852809f800 nid=0x7 in Object.wait() [0x00007f852ce53000]
"VM Thread" os_prio=0 tid=0x00007f8528095800 nid=0x6 runnable 
"VM Periodic Task Thread" os_prio=0 tid=0x00007f85280e5000 nid=0xd waiting on condition 

jstack -l 1 > 1.stack
导出线程文件

你可能感兴趣的:(2021-12-18 java性能分析)