Problem Description:
When performing performance tests on notify, it was found that the CPU load suddenly soared and CPU utilization was as high as 95%. It is time to troubleshoot which threads consume the CPU and find the "culprit" that consumes the CPU from the code layer.
Steps:
1. First use Ps+grep to find the process PID being tested.
For example: Ps–ef|grep notify, get PID 29128.
2. Execute Top-h-p to display all threads under the process. Find the most CPU-intensive child-thread PID and convert it to 16-binary.
For example: Top-h-P 29128, see all child threads of notify. Among them, the%cpu proportion of the largest sub-thread PID is 879, converted to 16 binary is 36f.
3. Execute jstack|less and find the child thread PID to see the stack information.
For example: Jstack 29128|less, and then find nid=0x36f, see the stack as follows
| "Dispatchertpconfig-6-thread-22" prio=10 tid=0x000000004dd84000 nid=0x36f runnable [0x000000004ae18000] Java.lang.Thread.State:RUNNABLE At Java.util.ArrayList.contains (arraylist.java:199) <notify related stack information hiding < span= "" >> ...... |
4. Follow the method information in the stack to navigate to the code, and the next step is to analyze the tuning.
Postscript:
This method can easily and quickly locate the cause of CPU consumption, but the accuracy is not ideal. If you want to drill down into the methods that consume CPU TOP10, you can use specialized profiling tools, such as Oprofile, perf, and so on.
CPU Performance bottleneck analysis case in Linux