当前位置:网站首页>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
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 .
This article from the Knowledge planet interview disassembly series , Welcome to play together ~
边栏推荐
- Iptables foundation and Samba configuration examples
- 担心“断气” 德国正修改《能源安全法》
- Oracle was named the champion of Digital Innovation Award by Ventana research
- FS7867S是一款应用于数字系统供电电源电压监控的电压检测芯片
- C语言小型商品管理系统
- Node の MongoDB安装
- SQL statement syntax error in test SQL statement deletion in eclipse linked database
- C#基础深入学习二
- ViewBinding和DataBinding的理解和区别
- 数据库公共字段自动填充
猜你喜欢
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
ASP. Net core introduction I
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
CVPR 2022 | transfusion: Lidar camera fusion for 3D target detection with transformer
2022年起重机械指挥考试模拟100题模拟考试平台操作
光环效应——谁说头上有光的就算英雄
Animation and transition effects
How real-time cloud interaction helps the development of education industry
Oracle was named the champion of Digital Innovation Award by Ventana research
Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务
随机推荐
Five "potential errors" in embedded programming
Rsyslog configuration and use tutorial
N++ is not reliable
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
Annual comprehensive analysis of China's mobile reading market in 2022
Configure WebDAV server on Apache
.NET 使用 redis
. Net delay queue
博士申请 | 西湖大学学习与推理系统实验室招收博后/博士/研究实习等
面试官:Redis中哈希数据类型的内部实现方式是什么?
E-week finance | Q1 the number of active people in the insurance industry was 86.8867 million, and the licenses of 19 Payment institutions were cancelled
C basic supplement
免费、好用、强大的轻量级笔记软件评测:Drafts、Apple 备忘录、Flomo、Keep、FlowUs、Agenda、SideNote、Workflowy
Samsung's mass production of 3nm products has attracted the attention of Taiwan media: whether it can improve the input-output rate in the short term is the key to compete with TSMC
"Tips" to slim down Seurat objects
Introduction to XML II
C语言程序设计
一次 Keepalived 高可用的事故,让我重学了一遍它
Node の MongoDB安装
Scrapy 框架学习