当前位置:网站首页>JVM performance tuning and monitoring tools -- JPS, jstack, jmap, jhat, jstat, hprof
JVM performance tuning and monitoring tools -- JPS, jstack, jmap, jhat, jstat, hprof
2022-06-27 13:26:00 【User 3147702】
1. summary
In the last article , We introduced what scenarios would cause java Memory leaks . However , In many cases , Memory leak 、 Out of memory 、CPU It is easy to restart the server in case of high occupancy 、 Add memory and other processing methods to hide , Most of the java Programmers don't go into the root of the problem . this paper , We're going to learn java Performance monitoring provided 、 Tuning Tools , To locate 、 Solve these problems that are easy to be hidden .
2. jps
jps (Java Virtual Machine Process Status Tool) Is used for output jvm Tools for running status information .
2.1. Grammar format
- jps [options] [hostid] If you don't specify hostid The default is the current host .
2.2. Command line optional parameters
- -q — Do not output class name 、Jar Name and pass in main Method parameters
- -m — Output incoming main Method parameters
- -l — Output main Class or Jar The full name of
- -v — Output incoming JVM Parameters of
2.3. example
[email protected] ~ $ jps -ml46082 com.intellij.database.remote.RemoteJdbcServer com.mysql.jdbc.Driver17125 org.jetbrains.jps.cmdline.Launcher /Applications/IntelliJ IDEA.app/Contents/lib/javac2.jar:/Applications/IntelliJ IDEA.app/Contents/lib/oromatcher.jar:/Applications/IntelliJ IDEA.app/Contents/lib/jgoodies-forms.jar:/Applications/IntelliJ IDEA.app/Contents/lib/asm-all.jar:/Applications/IntelliJ IDEA.app/Contents/lib/commons-codec-1.9.jar:/Applications/IntelliJ IDEA.app/Contents/lib/protobuf-2.5.0.jar:/Applications/IntelliJ IDEA.app/Contents/lib/httpcore-4.4.5.jar:/Applications/IntelliJ IDEA.app/Contents/lib/jna-platform.jar:/Applications/IntelliJ IDEA.app/Contents/lib/netty-all-4.1.10.Final.jar:/Applications/IntelliJ IDEA.app/Contents/lib/jps-model.jar:/Applications/IntelliJ IDEA.app/Contents/lib/util.jar:/Applications/IntelliJ IDEA.app/Contents/lib/slf4j-api-1.7.10.jar:/Applications/IntelliJ IDEA.app/Contents/lib/aether-1.1.0-all.jar:/Applications/IntelliJ IDEA.app/Contents/lib/snappy-in-java-0.5.1.jar:/Applications/IntelliJ IDEA.app/Contents/lib/jna.jar:/Applications/IntelliJ IDEA.app/Contents/lib/openapi.ja49302 sun.tools.jps.Jps -ml17128 org.jetbrains.jps.cmdline.Launcher /Applications/IntelliJ IDEA.app/Contents/lib/javac2.jar:/Applications/IntelliJ IDEA.app/Contents/lib/oromatcher.jar:/Applications/IntelliJ IDEA.app/Contents/lib/jgoodies-forms.jar:/Applications/IntelliJ IDEA.app/Contents/lib/asm-all.jar:/Applications/IntelliJ IDEA.app/Contents/lib/commons-codec-1.9.jar:/Applications/IntelliJ IDEA.app/Contents/lib/protobuf-2.5.0.jar:/Applications/IntelliJ IDEA.app/Contents/lib/httpcore-4.4.5.jar:/Applications/IntelliJ IDEA.app/Contents/lib/jna-platform.jar:/Applications/IntelliJ IDEA.app/Contents/lib/netty-all-4.1.10.Final.jar:/Applications/IntelliJ IDEA.app/Contents/lib/jps-model.jar:/Applications/IntelliJ IDEA.app/Contents/lib/util.jar:/Applications/IntelliJ IDEA.app/Contents/lib/slf4j-api-1.7.10.jar:/Applications/IntelliJ IDEA.app/Contents/lib/aether-1.1.0-all.jar:/Applications/IntelliJ IDEA.app/Contents/lib/snappy-in-java-0.5.1.jar:/Applications/IntelliJ IDEA.app/Contents/lib/jna.jar:/Applications/IntelliJ IDEA.app/Contents/lib/openapi.ja17146 org.jetbrains.idea.maven.server.RemoteMavenServer171023. jstack
jstack It is mainly used to view a certain Java In process thread stack information . The syntax is as follows :
3.1. Grammar format
- jstack [option] <pid> (to connect to process)
- jstack [option] <executable> <core> (to connect to a core file)
- jstack [option] [[email protected]]<remote server IP or hostname> (to connect to a remote debug server)
3.2. Command line arguments
jstack The command has the following optional parameters :
- -F — mandatory dump Threads , Usually used for the output of unresponsive thread information
- -m — mixed mode, Not only will it output Java Stack information , It will also output C/C++ Stack information ( such as Native Method )
- -l — long listings, Will print out additional lock information , It can be used in the lock of life and death jstack -l pid To observe lock holding
- -h or -help — Print help
3.3. Use — find java Most consumed in process CPU Code for
jstack It's for printing java Thread stack information in the process , Through the stack information, we can locate the specific code , stay jvm The tuning process uses a lot . Now let's talk about how to find a java Most consumed in process CPU Of java Threads .
Find out the process ID — ps First we pass ps Command found running on jetty In container java process pid.
Find occupancy CPU The longest thread — top -Hp pid Next , We go through top Command to find the occupation in the process CPU The longest thread ID.
We found the thread ID — 31078.
Output thread stack information — jstack First, through printf "%x\n" 31078 Command calculation thread ID Of 16 The base value is 7966, Next , We just need to call jstack,grep 7966 You can find it CPU What code is consumed .
We see that this thread is in waiting on condition The state of , Indicates that he is waiting for an event to trigger . adopt cat Combination of orders sed command , We can finally get the next few lines of data in this line :
"MnsCacheManager-Schedule-1-thread-1" #68 daemon prio=5 os_prio=0 tid=0x00007fd225e0f800 nid=0x7966 waiting on condition [0x00007fd108830000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000073b44d090> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)You can see , Threads in the TIMED_WAITING state , Indicates that the threads in this thread pool are sleeping , Waiting to wake up , And the timeout is set .
3.4. Location of deadlock problem
Deadlock is a very common and easily overlooked problem in code , Here's a jstack Output , It clearly shows the existence of deadlocks and the specific location of the code .
"t2" prio=5 tid=0x00007fd9d30ac000 nid=0x5903 waiting for monitor entry [0x000000011da46000]
java.lang.Thread.State: BLOCKED (on object monitor)
at DeadLock$2.run(DeadLock.java:38)
- waiting to lock <0x00000007aaba7e58> (a java.lang.Object)
- locked <0x00000007aaba7e68> (a java.lang.Object)
Locked ownable synchronizers:
- None"t1" prio=5 tid=0x00007fd9d30ab800 nid=0x5703 waiting for monitor entry [0x000000011d943000]
java.lang.Thread.State: BLOCKED (on object monitor)
at DeadLock$1.run(DeadLock.java:23)
- waiting to lock <0x00000007aaba7e68> (a java.lang.Object)
- locked <0x00000007aaba7e58> (a java.lang.Object)
Locked ownable synchronizers:
- NoneYou can see , Threads t1 Waiting for the lock , Threads t2 Waiting for the lock, too , Both sides also occupy the other side's waiting lock , Thus, the existence of deadlock can be easily determined .
4. jmap
jmap (JVM Memory Map) The command is used to generate heap dump file . You can also query through optional parameters finalize Perform the queue 、Java Heap and permanent generation details , Such as the current usage rate 、 What kind of collector is currently used .
4.1. jmap Grammar format
- jmap [option] <pid>
- jmap [option] <executable <core> (to connect to a core file)
- jmap [option] [[email protected]]<remote server IP or hostname> (to connect to remote debug server)
4.2. Optional parameters
- By default — Print heap memory dump The contents of the document
- -heap — Show java Heap details , Including the GC Algorithm 、 Heap configuration parameters and heap memory usage in each generation
- -histo — Displays the details of the objects in the heap
- -histo:live — Display the details of the surviving objects in the heap
- -permstat — Show java Persistent generation classloader statistics in heap memory
- -finalizerinfo — Displayed in the F-Queue Waiting in the queue for execution finalizer Object of method
- -dump — Generate a roll out snapshot of heap memory
- -F — -dump When there is no response , Force snapshot generation
4.3. explain
It should be noted that , If you start with java Version and jmap The version of is different , You're going to report a mistake . This usually happens when multiple versions of the are installed on the machine jdk package , You need to look for the version you need to use .
[[email protected] ~]$ jmap -heap 22845Attaching to process ID 22845, please wait...
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.tools.jmap.JMap.runTool(JMap.java:197)
at sun.tools.jmap.JMap.main(JMap.java:128)
Caused by: sun.jvm.hotspot.runtime.VMVersionMismatchException: Supported versions are 24.76-b04. Target VM is 25.45-b02
at sun.jvm.hotspot.runtime.VM.checkVMVersion(VM.java:234)
at sun.jvm.hotspot.runtime.VM.<init>(VM.java:297)
at sun.jvm.hotspot.runtime.VM.initialize(VM.java:368)
at sun.jvm.hotspot.bugspot.BugSpotAgent.setupVM(BugSpotAgent.java:598)
at sun.jvm.hotspot.bugspot.BugSpotAgent.go(BugSpotAgent.java:493)
at sun.jvm.hotspot.bugspot.BugSpotAgent.attach(BugSpotAgent.java:331)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:163)
at sun.jvm.hotspot.tools.HeapSummary.main(HeapSummary.java:40)
... 6 more5. jhat
If you think jmap The printed results are not intuitive , Don't worry ,java It also provides an easy-to-use browser interface analysis tool jhat. JVM Heap Analysis Tool The order is with jmap Use it with , Used for analysis jmap Generated dump,jhat Built in a micro HTTP/HTML The server , Generate dump After analyzing the results of , You can view... In a browser .
5.1. Usage mode
First, through jmap Output heap memory dump file
then , adopt jhat Command specifies the port , You can view it in the browser
5.2. Print field meaning
- S0C、S1C、S0U、S1U — Survivor 0/1 Area capacity (Capacity) And usage (Used)
- EC、EU — Eden Area capacity and usage
- OC、OU — Capacity and usage of older generations
- PC、PU — Permanent generation capacity and usage
- YGC、YGT — The younger generation GC Times and GC Time consuming
- FGC、FGCT — Full GC Times and Full GC Time consuming
- GCT — GC Total time
6. Reference material
Yu Huo — http://www.cnblogs.com/myna/ JVM Performance tuning monitoring tool jps、jstack、jmap、jhat、jstat、hprof The use of, — https://blog.csdn.net/dragonassassin/article/details/51010947.
边栏推荐
- Size end byte order
- Airbnb复盘微服务
- 基于SSM实现招聘网站
- To understand again is the person in the song
- Configuration management center of microservices
- 【TcaplusDB知识库】TcaplusDB-tcapulogmgr工具介绍(一)
- Using FRP tool to realize intranet penetration
- Nifi from introduction to practice (nanny level tutorial) - identity authentication
- 夏日里的清凉
- [weekly replay] the 81st biweekly match of leetcode
猜你喜欢
随机推荐
Viewpager2 usage record
抖音实战~公开/私密短视频互转
Pycharm in Chinese
How to choose LAN instant messaging software
[medical segmentation] unet3+
动态规划
crane:字典项与关联数据处理的新思路
基于JSP实现医院病历管理系统
VS调试技巧
Cesium实现卫星在轨绕行
jvm 性能调优、监控工具 -- jps、jstack、jmap、jhat、jstat、hprof
隐私计算FATE-离线预测
C语言 函数指针与回调函数
快讯:华为启动鸿蒙开发者大赛;腾讯会议发布“万室如意”计划
GCC compiling dynamic and static libraries
Today's sleep quality record 78 points
【动态规划】—— 背包问题
[weekly replay] the 81st biweekly match of leetcode
Local visualization tool connects to redis of Alibaba cloud CentOS server
手把手教你搭一个永久运行的个人服务器!









