当前位置:网站首页>Real case: how to check the soaring usage of CPU after the system goes online?
Real case: how to check the soaring usage of CPU after the system goes online?
2022-07-19 08:14:00 【Young】

In fact, this is a very common problem , It's very simple , In that case, why should I write ? Because last time I answered, I forgot to thread PID convert to 16 Hexadecimal command .
So I decided to review this question again , Of course, I also prepared the test code for you , You can actually operate it , So I won't forget next time .
Simulate a high CPU scene
public class HighCpuTest {
public static void main(String[] args) {
List<HignCpu> cpus = new ArrayList<>();
Thread highCpuThread = new Thread(()->{
int i = 0;
while (true){
HignCpu cpu = new HignCpu("Young、",i);
cpus.add(cpu);
System.out.println("high cpu size:" + cpus.size());
i ++;
}
});
highCpuThread.setName("HignCpu");
highCpuThread.start();
}
}
stay main Method opens a thread , Infinite build HighCpu object .
@Data
@AllArgsConstructor
public class HignCpu {
private String name;
private int age;
}
Prepare the above code , function HighCpuTest, Then you can start some column operations to find the cause of the problem .
Troubleshooting steps
First step , Use top Find occupancy CPU The highest Java process
1. monitor cpu Running state , Displays a list of process running information
top -c
2. Press CPU Usage sort , Type in uppercase P
P

The second step , use top -Hp Command view occupancy CPU The highest thread
The last step is to use top The order found that Java process . There are so many threads in that process , It is impossible that all threads are occupied all the time CPU Don't put , This step is to find out the culprit , Of course, there may be more than one .
perform top -Hp pid command ,pid It's the one in front Java process , In my case 16738 , The complete order is :
top -Hp 16738, Then type. P ( Capitalization p), According to the thread CPU Usage sort
The effect after execution is as follows

It's found that CPU The highest thread PID by 16756
The third step , View stack information , Locate the corresponding code
adopt printf The command converts it into 16 Base number , The reason why it needs to be transformed into 16 Base number , Because in the stack , Threads id Yes, it is 16 In base notation .( I just forgot this order ~)
[[email protected] ~]# printf "%x\n" 16756
4174
obtain 16 Base thread ID by 4174.
adopt jstack Command to view stack information
jstack 16738 | grep '0x4174' -C10 --color

Pictured above , Find the consumption CPU The thread name corresponding to the high thread “HighCpu”, And see the stack where the thread is executing the code .
Last , According to the information in the stack , Locate the corresponding dead loop code , Get it done .
Summary
cpu How to check after the usage rate soars This question is not only often asked in interviews , And it is also very useful in practical work , You'd better practice according to the above steps , Only in this way can we remember well .
边栏推荐
- csp-2020-6-《角色授权》
- [C# Console]-C# 控制臺類
- 2022 review questions and mock exams for main principals of hazardous chemical business units
- Yolov5 label and establish your own data set
- Redis transaction
- Go语言圣经
- RNN convolutional neural network
- Is it necessary to buy pension insurance? What are the pension products suitable for the elderly?
- 聊聊分布式锁
- RISC-V技術雜談
猜你喜欢

Database review -- database recovery technology

New redis6 features

Xinlinx zynq7020, 7045 domestic replacement fmql45t900 national production arm core board + expansion board

812. 最大三角形面积

xgboos-hperopt

深圳保诚笔试记录

Visual studio production environment configuration scheme: slowcheetah

【flask入门系列】请求钩子与上下文

会话技术【黑马入门系列】

leetcode:287. 寻找重复数【快慢指针板子】
随机推荐
面试题:外边距折叠问题 (块级元素在普通文档流中的BUG)
Deep learning 7 deep feedforward network 2
Paddleserving服务化部署 tensorrt报错, shape of trt subgraph is [-1,-1,768],
Use of fiddler packet capturing tool
黑马程序员-软件测试-16阶段3-功能测试-175-198,URL组成介绍,请求内容以及组成说明行功能测试与数据库,url组成扩展说明,客户端与服务器请求与响应,-Fiddler按照以及功能检查确认,
《痞子衡嵌入式半月刊》 第 58 期
Shenzhen Prudential written examination record
Csp-2020-6- role authorization
CCF-CSP《202206-2—寻宝!大冒险!》
xgboos-hperopt
mysql语句的注意事项
写代码遇到Qt相关问题
美联储降息,为何长期利好数字货币市场? 2020-03-05
[C console] - C console class
串口通讯到底有没有累积误差及对时钟精度的要求
First experience of openvino machine learning
Unity custom sky ball model to prevent it from being cropped
Redis cache avalanche, penetration, breakdown
Convolutional neural network CNN
How does the V8 engine recycle garbage memory?