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

Recommend

Nginx reverse proxy to go-fastdfs case explanation

background go-fastdfs is a distributed file syste...

Example of using Docker Swarm to build a distributed crawler cluster

During the crawler development process, you must ...

MySQL select results to perform update example tutorial

1. Single table query -> update UPDATE table_n...

Tutorial on using Webpack in JavaScript

Table of contents 0. What is Webpack 1. Use of We...

Detailed tutorial of pycharm and ssh remote access server docker

Background: Some experiments need to be completed...

docker-maven-plugin packages the image and uploads it to a private warehouse

Table of contents 1. Introduction to docker-maven...

Knowledge about MySQL Memory storage engine

Knowledge points about Memory storage engine The ...

Two practical ways to enable proxy in React

Two ways to enable proxy React does not have enca...

Detailed explanation of memory management of MySQL InnoDB storage engine

Table of contents Storage Engine Memory Managemen...

Initial summary of the beginner's website building tutorial

After writing these six articles, I started to fee...

favico.ico---Website ico icon setting steps

1. Download the successfully generated icon file, ...

How to install and uninstall open-vswitch in Linux

1. Compile and install ovs from source code: Inst...

Use iframe to submit form without refreshing the page

So we introduce an embedding framework to solve th...

HTML page common style (recommended)

As shown below: XML/HTML CodeCopy content to clip...