当前位置:网站首页>Interview disassembly: how to check the soaring usage of CPU after the system goes online?
Interview disassembly: how to check the soaring usage of CPU after the system goes online?
2022-07-04 13:54:00 【Misty jam】
Hello everyone , I am ethereal .
Last time the interviewer asked a question : After the application goes online Cpu How to check the soaring usage ?
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("Java Rizhilu ",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
4174obtain 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 .
This article from the Knowledge planet interview disassembly series , Welcome to play together ~

边栏推荐
- C#基础深入学习一
- Lick the dog until the last one has nothing (state machine)
- Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
- Read the BGP agreement in 6 minutes.
- 光环效应——谁说头上有光的就算英雄
- Distributed base theory
- Solution: how to delete the information of Jack in two tables with delete in one statement in Oracle
- 易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
- Database lock table? Don't panic, this article teaches you how to solve it
- C语言小型商品管理系统
猜你喜欢

2022年起重机械指挥考试模拟100题模拟考试平台操作

MySQL 45 lecture - learn the actual combat notes of MySQL in Geek time 45 lecture - 06 | global lock and table lock_ Why are there so many obstacles in adding a field to the table

结合案例:Flink框架中的最底层API(ProcessFunction)用法

When MDK uses precompiler in header file, ifdef is invalid

面试官:Redis中哈希数据类型的内部实现方式是什么?

Automatic filling of database public fields

2022KDD预讲 | 11位一作学者带你提前解锁优秀论文

Comparative study of the gods in the twilight Era

2022kdd pre lecture | 11 first-class scholars take you to unlock excellent papers in advance

Source code compilation and installation of MySQL
随机推荐
C語言宿舍管理查詢軟件
C语言职工管理系统
8 expansion sub packages! Recbole launches 2.0!
Go 语言入门很简单:Go 实现凯撒密码
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
Openharmony application development how to create dayu200 previewer
Is the outdoor LED screen waterproof?
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
面试拆解:系统上线后Cpu使用率飙升如何排查?
美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
MySQL three-level distribution agent relationship storage
Scripy framework learning
易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
"Pre training weekly" issue 52: shielding visual pre training and goal-oriented dialogue
Practice: fabric user certificate revocation operation process
Optional values and functions of the itemized contenttype parameter in the request header
#yyds干货盘点# 解决名企真题:连续最大和
Alibaba cloud award winning experience: build a highly available system with polardb-x
Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务