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

边栏推荐
- Deploy halo blog with pagoda
- 美国土安全部部长警告移民“不要踏上危险的旅程”
- Fs4056 800mA charging IC domestic fast charging power IC
- Source code compilation and installation of MySQL
- Apache server access log access Log settings
- Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
- JVM series - stack and heap, method area day1-2
- 8 expansion sub packages! Recbole launches 2.0!
- One of the solutions for unity not recognizing riders
- Oracle 被 Ventana Research 评为数字创新奖总冠军
猜你喜欢
Automatic filling of database public fields
CommVault cooperates with Oracle to provide metallic data management as a service on Oracle cloud
8 expansion sub packages! Recbole launches 2.0!
.Net之延迟队列
N++ is not reliable
Getting started with the go language is simple: go implements the Caesar password
分布式BASE理论
Comparative study of the gods in the twilight Era
[cloud native | kubernetes] in depth understanding of ingress (12)
Efficient! Build FTP working environment with virtual users
随机推荐
Alibaba cloud award winning experience: build a highly available system with polardb-x
FS4056 800mA充电ic 国产快充电源ic
Configure WebDAV server on Apache
C#基础补充
Introduction to XML II
提高MySQL深分页查询效率的三种方案
C foundation in-depth study I
WPF double slider control and forced capture of mouse event focus
易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
HAProxy高可用解决方案
Excuse me, have you encountered this situation? CDC 1.4 cannot use timestamp when connecting to MySQL 5.7
Iptables foundation and Samba configuration examples
The old-fashioned synchronized lock optimization will make it clear to you at once!
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
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
SQL language
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
. Net using redis
Getting started with microservices
.NET 使用 redis