Deploy a server on a number of tomcat instance, that a number of vertical segmentation of Java site services, as well as a number of Java micro-services, operation and maintenance of a sudden receive CPU abnormal alarm.
Q: How is positioning which service processes lead to CPU overload, which thread cause CPU overload, what code cause CPU overload?
Step one, find the most consuming CPU process PID
Tools : Top
Methods :
· Execution Top -c , displays a list of processes running information
· Type P ( uppercase the p-) , in accordance with the process CPU usage sort
Step two: find within this process consuming the most CPU threads of PID
Tools : Top
Methods :
· Top -Hp 10765 , threads of a process of displaying a list of operational information
· Type P ( uppercase the p-) , according to the thread CPU sort usage
Step 3: Thread PID converted into 16 hex
Tools : printf
Methods : printf "the X-% \ the n-" 10804
This step can use a calculator . The reason for the conversion of 16 hex, because the stack, thread id is 16 hexadecimal representation.
Step four: Check the stack to find the thread doing
Tools : pstack / jstack / grep
Methods : jstack 10765 | grep '0x2a34' --color-C5
· Printing process stack
· By thread the above mentioned id , and filtered to give the thread stack
We found the consumption of CPU threads corresponding to the thread name high " AsyncLogger-1 ", and see the thread stack is executing the code.