How to find the high CPU usage of java web application under linux

There is cpu consumption analysis in java performance tuning. Now I record the analysis process of high cpu usage (usually too high or sy is too high. In this chapter, we take too high us as an example)

1. Use the top or pidstat command to view the process consumption under linux. Use the top command in the following figure

illustrate:

The usage of us is too high, which is also called the high CPU usage in user space. The process is: 31808

2. Next, we find the thread that occupies a higher CPU. Press the H key to switch the display process or thread, and then press Enter, as shown below

illustrate:

You can see that there are two higher threads, 31849 and 31850

 

3. We first look for the code with too high thread 31849, and convert it to hexadecimal first. You can use printf %x xxx, as shown in the figure below, which is converted to 7c69

 

 

4. Finally, use the jstack command to locate the code (set the jdk environment variable). Where -A 4 is the last 4 lines of the search line, and 7c69 is the hexadecimal thread pid.


Or find the bin directory of java and execute: ./jstack -l 18121 |grep -A 4 46eb 

jstack [-l] <pid>

        (to connect to running process)

    jstack -F [-m] [-l] <pid>

        (to connect to a hung process)

    jstack [-m] [-l] <executable> <core>

        (to connect to a core file)

    jstack [-m] [-l] [server_id@]<remote server IP or hostname>

 

        (to connect to a remote debug server)

 

Finally, we can locate the run method of ImportResThread.

Below is the thread class for my test


 

原因:执行线程没有任何挂起动作,且一直执行,导致CPU 没有机会去调度执行其他的线程。导致us过高。

 

ps:sy过高的原因一般为线程数过过,竞争激烈,上下文切换频繁。

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326500793&siteId=291194637