What happens when CPU or memory usage is too high

During the development process, sometimes we find that the CPU / memory occupied by the JVM remains high, which is inconsistent with our expectations. At this time, what is the CPU doing? What thread makes CPU / memory so busy? We can see what threads the CPU is executing through the following steps.

1. The top command checks the processes with high CPU / memory occupation (P is sorted by CPU occupation and M is sorted by memory occupation), and records the PID of the processes

2. Top - HP PID view the thread information of the process (P is sorted by CPU occupation, M is sorted by memory occupation), and record the TID of the thread

3. Convert TID to hexadecimal number: printf "% X \ n" tid

4. Use the jstack command to query the thread information to locate the specific thread and code: jstack PID | grep 6f8a - a 30

In this way, you can see why the CPU / memory occupation is so high and what threads are making trouble!

5. The extreme point is to export all the thread stacks of the process, and then locate what the TID thread is doing: jstack 18023 > / home / wwwroot / dump18023

6. Count the status of threads, grep Java lang.Thread. State dump18023 | awk '{print $2$3$4$5}' | sort | uniq -c

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>