Find the thread with high CPU usage

Problem description:
A tomcat7 server in the production environment, everything was normal when it was first released, but after running for a period of time, there was a problem of high CPU usage, basically the load was getting higher day by day.

Analysis of the problem:
1. The program is CPU-intensive, and we have communicated with the developer to rule out such a situation.
2. There is a problem with the program code, and there is a great possibility of an infinite loop.

Problem solving:
1. The development side cannot check that there is a problem with a certain module of the code, and it cannot be analyzed from the log.
2. I remember that the problem of high CPU usage of a PHP server was solved by the strace tracking method, but this method is invalid. After google search, I found that it can be solved by the following method, then try it.

Solution:
1. According to the top command, it is found that the Java process with PID 2633 occupies up to 300% of the CPU and is faulty.

2. After finding the process, how to locate the specific thread or code? First, display the thread list and sort them according to the threads with high CPU usage:
[root@localhost logs]# ps -mp 2633 -o THREAD,tid,time | sort - rn

shows the result as follows:
USER %CPU PRI SCNT WCHAN USER SYSTEM TID TIME
root 10.5 19 - - - - 3626 00:12:48
root 10.1 19 - - - - 3593 00:12:16

Found the most time-consuming thread 3626, which took up 12 minutes of CPU time!

Convert the required thread ID to hexadecimal format:
[root@localhost logs]# printf "%x\n" 3626
e18

Finally print the stack information of the thread:
[root@localhost logs]# jstack 2633 |grep e18 -A 30


The problematic code can be identified by the output information.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326767340&siteId=291194637