当前位置:网站首页>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 ~

边栏推荐
- Dgraph: large scale dynamic graph dataset
- 结合案例:Flink框架中的最底层API(ProcessFunction)用法
- C语言小型商品管理系统
- Introduction to reverse debugging PE structure resource table 07/07
- XILINX/system-controller-c/BoardUI/无法连接开发板,任意操作后卡死的解决办法
- 担心“断气” 德国正修改《能源安全法》
- [FAQ] summary of common causes and solutions of Huawei account service error 907135701
- Using nsproxy to forward messages
- 数据库公共字段自动填充
- Scripy framework learning
猜你喜欢

基于链表管理的单片机轮询程序框架

Reptile exercises (I)

高质量软件架构的唯一核心指标

Openharmony application development how to create dayu200 previewer

安装trinity、解决报错

One of the solutions for unity not recognizing riders

Animation and transition effects

A data person understands and deepens the domain model

JVM系列——栈与堆、方法区day1-2

Source code compilation and installation of MySQL
随机推荐
HAProxy高可用解决方案
C语言宿舍管理查询软件
Introduction to XML II
舔狗舔到最后一无所有(状态机)
Comparative study of the gods in the twilight Era
Read the BGP agreement in 6 minutes.
数据库公共字段自动填充
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
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
C语言个人通讯录管理系统
Flet tutorial 03 basic introduction to filledbutton (tutorial includes source code) (tutorial includes source code)
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍
The only core indicator of high-quality software architecture
AI painting minimalist tutorial
"Tips" to slim down Seurat objects
Alibaba cloud award winning experience: build a highly available system with polardb-x
c#数组补充
C foundation in-depth learning II
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
Excuse me, have you encountered this situation? CDC 1.4 cannot use timestamp when connecting to MySQL 5.7