Problem Description:
When performing performance tests on notify, the CPU load was suddenly high and CPU utilization was up to 95%. This is the time to troubleshoot which threads consume the CPU, and from the code layer to find CPU-hogging "culprit."
steps:
1. First use Ps+grep to find the process PID being tested.
For example: Ps–ef|grep notify, get PID is 29128.
2. Execute Top-h-P <pid>, which shows all threads under the process. Locate the most CPU-consuming child thread PID and convert it to 16.
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 is 36f.
3. Perform Jstack <pid>|less, find the thread PID to see the stack information.
For example: Jstack 29128|less, and then look for 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 > ...... |
4. The method information in the follow-up stack is positioned to the code, and the next step is to analyze the tuning.
PostScript:
This method can simply and quickly locate the reason of CPU consumption, but the accuracy is not ideal. If you want to drill down to the CPU Top10 method, you can use specialized profiling tools, such as Oprofile, perf.