preface

During the development process, it is common for a deployed project to suddenly experience a problem of high CPU usage after running for a period of time, which can lead to an increase in service response time or even downtime

Analysis of the

  1. Run the top command to check the CPU usage of the process

2. Find the PID of the Java program and run the top-h -p pid command to check the CPU usage of all threads in the process

top -H -p  5085
Copy the code

3. Locate the THREAD with the highest CPU usage. Pid is the ID of the THREAD

4. Change the thread id into hexadecimal, reoccupy jstack pid | grep thread id information can view the thread’s stack

Copy the code

Then you can go with the stack information points why the thread take up very high, the above two cases, if is a figure, we can according to the above the class name of the thread and lines of code to analyzing code to determine the cause of the high CPU, if is figure 2, represents the highest CPU gc thread, you will need to continue to analysis

5. Run the jstat command to view GC logs

Jstat -gc PID 3000 3000 Indicates that the output is generated every three secondsCopy the code

S0C: S0 capacity (same in S1, omitted) S0U: USED in S0 EC: used in E EU: used in E OC: used in an old age OU: used in an old age PC: Perm capacity PU: used in Perm YGC: Young Number of GC (Minor GC) cycles YGCT: Young Total GC duration FGC: Full Number of GC cycles Xmx512m [file] FGCT: Full Total GC duration GCT: Total GC durationCopy the code

If you find a high number and frequency of FGC, there is no doubt that there is something wrong with your program. Jstack and JMAP are used to analyze heap memory usage. Jmap-dump :format=b,file=heapdump.phrof pid command to generate dump files and use proprietary software such as jprofiler

Of course, this software can also be used in the development, can be very intuitive through the interface to see the process of program running stack, thread, and other information, convenient and fast positioning problems.

Just select your program that is running