In the long-term troubleshooting of the process of online problems, summed up the use of some tools and troubleshooting ideas, here to share with you, in the face of similar problems, I hope to give some help.
First of all, there are tools that the JVM comes with, such as Jstack, Jmap, Jstat, and so on, that can help us understand what the JVM is doing, the main areas of application:
1, Jstack
Jstack can tell you what the current JVM threads are doing, including the user thread and the virtual machine thread, which you can use to view the thread stacks, and combine the lock information to detect if a deadlock or deadlock has occurred.
It's okay. Jstack, know what your little buddy is doing.
In addition, when using TOP-H to see the CPU very high PID, can be converted to 16 binary after the Jstack dump out of the file search, to see exactly what thread occupied the CPU.
2, Jstat
Stat, as the name implies, provides some statistical information, it can tell you the current GC situation, including GC number, time, specific GC can also be combined with Gc.log file analysis.
In general, we use Jstat to check the GC situation, to determine if there are YGC or FGC frequent cases, then to see Gc.log and Jamp dump memory, MAT analysis to locate the problem (there will be a case for this scenario).
The common usage is jstat-gcutil pid time_interval
3, Jmap
A tool that will inevitably be used to troubleshoot GC problems, Jmap can tell you about the distribution of objects in the current JVM memory heap and their relationships, and when you dump the heap you can analyze it with a mat to see what the big objects are, or which instances of the classes are especially large.
Common usage:
Mandatory fgc:-histo:live
Dump Heap:-dump:[live],format=b,file=dump.bin
To view the memory consumption of each generation:-heap
Then let's introduce some open source tools to enhance the role of the JVM tools themselves.
4. Top
This is the Linux command, to see the system resource consumption, you can see the CPU, memory, SWAP, I/O consumption, there are several values that require special attention:
NI, if this value is particularly high, indicates that thread context switching is expensive, to see if it is causing too many threads to open.
Res, which represents the actual memory occupied by the process
Swap, the memory is not enough to occupy swap space, this time the general application performance will drop sharply, need special attention
Common tools and methods for troubleshooting Java applications online