JVM调优常用命令
参考了Hinsteny-Hisoka的文章,感谢
https://www.jb51.net/article/147702.htm
查看当前机器上所有运行的java进程名称与pid(进程编号)
jps -l
[self@owen-first ~]# jps -l 1712 helloworld.jar 3702 toSay-1.1.1.jar 21994 sun.tools.jps.Jps 1100 com.aliyun.tianji.cloudmonitor.Application
查看指定的jvm进程所有的属性设置和配置参数
jinfo pid
查看某个pid进程对应的应用程序内存占用情况
jmap -heap pid
[self@owen-first ~]# jmap -heap 3702 Attaching to process ID 3702, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.161-b12 using thread-local object allocation. Mark Sweep Compact GC Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 268435456 (256.0MB) NewSize = 67108864 (64.0MB) MaxNewSize = 134217728 (128.0MB) OldSize = 67108864 (64.0MB) NewRatio = 1 SurvivorRatio = 8 MetaspaceSize = 21807104 (20.796875MB) CompressedClassSpaceSize = 1073741824 (1024.0MB) MaxMetaspaceSize = 17592186044415 MB G1HeapRegionSize = 0 (0.0MB) Heap Usage: New Generation (Eden + 1 Survivor Space): capacity = 70582272 (67.3125MB) used = 47699728 (45.49000549316406MB) free = 22882544 (21.822494506835938MB) 67.58032385242572% used Eden Space: capacity = 62783488 (59.875MB) used = 43811552 (41.781951904296875MB) free = 18971936 (18.093048095703125MB) 69.78196560216597% used From Space: capacity = 7798784 (7.4375MB) used = 3888176 (3.7080535888671875MB) free = 3910608 (3.7294464111328125MB) 49.85618270745798% used To Space: capacity = 7798784 (7.4375MB) used = 0 (0.0MB) free = 7798784 (7.4375MB) 0.0% used tenured generation: capacity = 78106624 (74.48828125MB) used = 53877384 (51.38147735595703MB) free = 24229240 (23.10680389404297MB) 68.97927632872725% used 31332 interned Strings occupying 3263472 bytes.
查看进程所包含所有线程的Java堆栈信息
[self@owen-first ~]# jstack 3702 2019-11-14 14:23:22 Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.161-b12 mixed mode): "Attach Listener" #1743 daemon prio=9 os_prio=0 tid=0x00007f13600ac000 nid=0x5533 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE "pool-3-thread-37" #1688 prio=5 os_prio=0 tid=0x00007f135ca08000 nid=0x51eb waiting on condition [0x00007f1354c8b000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x00000000f4356e20> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039) at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442) at run.halo.app.event.post.AbstractVisitEventListener$PostVisitTask.run(AbstractVisitEventListener.java:101) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) ...... "Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007f138809c800 nid=0xe79 in Object.wait() [0x00007f138e3bd000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:502) at java.lang.ref.Reference.tryHandlePending(Reference.java:191) - locked <0x00000000f802b410> (a java.lang.ref.Reference$Lock) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153) "VM Thread" os_prio=0 tid=0x00007f1388095000 nid=0xe78 runnable "VM Periodic Task Thread" os_prio=0 tid=0x00007f13880e0800 nid=0xe7f waiting on condition JNI global references: 2336
可以实时监测系统资源占用与jvm运行情况,全称:“Java Virtual Machine statistics monitoring tool”。
// 命令语法结构: Usage: jstat -help|-options jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]] // 参数解释: Options — 选项,我们一般使用 -gcutil 查看gc情况 vmid — VM的进程号,即当前运行的java进程号 interval– 间隔时间,单位为秒或者毫秒 count — 打印次数,如果缺省则打印无数次 S0 — Heap上的 Survivor space 0 区已使用空间的百分比 S1 — Heap上的 Survivor space 1 区已使用空间的百分比 E — Heap上的 Eden space 区已使用空间的百分比 O — Heap上的 Old space 区已使用空间的百分比 P — Perm space 区已使用空间的百分比 YGC — 从应用程序启动到采样时发生 Young GC 的次数 YGCT– 从应用程序启动到采样时 Young GC 所用的时间(单位秒) FGC — 从应用程序启动到采样时发生 Full GC 的次数 FGCT– 从应用程序启动到采样时 Full GC 所用的时间(单位秒) GCT — 从应用程序启动到采样时用于垃圾回收的总时间(单位秒) //示例 jstat -options -class -compiler -gc -gccapacity -gccause -gcmetacapacity -gcnew -gcnewcapacity -gcold -gcoldcapacity -gcutil -printcompilation [self@owen-first ~]# jstat -class -t 3702 Timestamp Loaded Bytes Unloaded Bytes Time 176180.9 17036 30914.4 211 302.6 21.65
以GUI的方式更直观化呈现jvm进程的实时情况,比如内存占用, 线程执行情况等
在jdk_home/bin目录下执行 jconsole.exe 打开图形化界面
一个付费的商业jvm分析监控工具, 可查看概况, 内存, GC活动, class 状况, 线程信息, CPU 占用情况, 内存对象信息, 还有数据库连接等, 是一个非常优秀的分析工具