Detailed explanation of the process of troubleshooting the cause of high CPU usage under Linux

Detailed explanation of the process of troubleshooting the cause of high CPU usage under Linux

Preface

High CPU usage is a common online problem. If you don't know how to do this, it's really a bit disappointing.

insert image description here

Don't worry, brother, I'll teach you a combo.

start

Let's start with a project. The entire API, when we request /cpu/{count}, we can manually increase the CPU. Smart ghost~

    @GetMapping("/cpu/{count}")
    public long cpuTest(@PathVariable("count") long count) {
        long number = 0;
        for (int i = 0; i < count; i++) {
            number++;
        }
        return number;
    }

Pack, upload, and start

insert image description here

It's running. Remember the process number 14849.

Let's first look at the CPU usage under normal circumstances.

insert image description here

Very reasonable

Simulate online CPU surge

We request the /cpu/{100000000000} interface to increase the CPU usage, and use top to observe the CPU usage.

insert image description here

Directly work to 98%, very nice

OK, let's get started. We have a problem online now. The CPU is always very high. The boss asked you to find the reason and start to support it.

In fact, we now know who raised the CPU, but it is not detailed enough. It is far from enough to know which project has the problem. We should find the culprit, which method and how many lines caused the problem, so that the boss can call him an expert.

step

jps+top locates the application process

pidtop -Hp {pid} find the thread tid

Convert tid to hexadecimal printf "%x\n" {tid}

Print stack information jstack

Filter out what we want

Troubleshooting

The process id has been determined to be 14849. The next step is to find which thread is causing the problem.

Top -Hp 14849

insert image description here

It's obviously this 14908 who did it.

Convert to hexadecimal

insert image description here

Print Stack

insert image description here

The stack trace shows that the problem is on line 20 in TestController. Let’s go into code verification.

insert image description here

No big problem

Solve the case

Sprinkle flowers

This is the end of this article about the detailed troubleshooting process of high CPU speed under Linux. For more relevant content on troubleshooting high CPU speed under Linux, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of Linux CPU load and CPU utilization
  • Troubleshooting ideas and solutions for high CPU usage in Linux systems

<<:  CSS3 realizes the glowing border effect

>>:  Simple example of HTML checkbox and radio style beautification

Blog    

Recommend

How to forget the root password in Mysql8.0.13 under Windows 10 system

1. First stop the mysql service As an administrat...

Advanced and summary of commonly used sql statements in MySQL database

This article uses examples to describe the common...

The easiest way to make a program run automatically at startup in Linux

I collected a lot of them, but all ended in failu...

WeChat applet implements simple calculator function

WeChat applet: Simple calculator, for your refere...

HTML+CSS div solution when relative width and absolute width conflict

Div solution when relative width and absolute wid...

Summary of Linux ps and pstree command knowledge points

The ps command in Linux is the abbreviation of Pr...

HTML web page image tag

Insert image tag <IMG> The colorful web page...

Optimize MySQL with 3 simple tweaks

I don't expect to be an expert DBA, but when ...

How to delete node_modules and reinstall

Table of contents Step 1: Install node_modules in...

Linux CentOS 6.5 Uninstall, tar and install MySQL tutorial

Uninstall the system-provided MySQL 1. Check whet...

Design a data collector with vue

Table of contents Scenario Core Issues Status mon...

How to modify port 3389 of Windows server 2008 R2 remote desktop

The default port number of the Windows server rem...

MySQL 8.0.19 installation detailed tutorial (windows 64 bit)

Table of contents Initialize MySQL Install MySQL ...

Summary and analysis of commonly used Docker commands and examples

Table of contents 1. Container lifecycle manageme...