Troubleshooting ideas and solutions to the problem of high CPU usage in Linux systems

This article mainly introduces to you the troubleshooting ideas and solutions to the problem of high CPU usage in Linux systems. The article introduces it in great detail through sample code. It has certain reference learning value for everyone to learn or use Linux. Friends who need it Let’s learn together

Preface

As Linux operation and maintenance engineers, in our daily work, we will encounter situations where the CPU load on the Linux server reaches 100% and remains high. If the CPU continues to run high, it will affect the normal operation of the business system and cause losses to the enterprise.

Many operation and maintenance students are often at a loss when encountering this situation. For CPU overload problems, the following two methods can usually be used to quickly locate:

method one

Step one: use

top command, then press shift+p to sort by CPU

Find the pid of the process that takes up too much CPU

Step 2: Use

top -H -p [process id]

Find the ID of the thread with the highest resource consumption in the process

Step 3: Use

echo ‘obase=16;[thread id]’ | bc or printf “%x\n” [thread id]

Convert thread id to hexadecimal (letters should be lowercase)

bc is the calculator command of linux

Step 4: Execute

jstack [process id] |grep -A 10 [thread id in hexadecimal]”

View thread status information

Method Two

Step one: use

top command, then press shift+p to sort by CPU

Find processes that are taking up too much CPU

Step 2: Use

ps -mp pid -o THREAD,tid,time | sort -rn

Get thread information and find threads that occupy high CPU

Step 3: Use

echo ‘obase=16;[thread id]’ | bc or printf “%x\n” [thread id]

Convert the required thread ID to hexadecimal format

Step 4: Use

jstack pid |grep tid -A 30 [hexadecimal of thread id]

Print the stack information of the thread

case analysis

Combine the above.

scene description

Troubleshooting high CPU usage of JAVA process in production environment

Resolution process

1. According to the top command, shift+p, it was found that the Java process with PID 41673 occupied up to 250% of the CPU and malfunctioned.
2. After finding the process, how to locate the specific thread or code? First display the thread list and sort by threads with high CPU usage:

[root@localhost ~]# ps -mp 41673 -o THREAD,tid,time | sort -rn

The displayed results are as follows:

3. Convert the required thread TID to hexadecimal format

[root@localhost ~]# printf "%x\n" 41846
a376

4. Finally, use the jstack command to print out the stack information of this thread under the process:

[root@localhost ~]# jstack 41673 |grep "a376" -A 30

Solution

1. According to the top command, shift+p, it was found that the Java process with PID 41673 occupied up to 250% of the CPU and malfunctioned.

2. Check his process based on the pid to see what service is occupying such a high level.

ps -ef |grep -v grep | grep 41673


3. Check that a java process has such a high usage, and then see if it is useful. If not, kill it.

kill -9 41673

4. Use top again to check that the overall CPU has dropped.

Summarize

The above is the entire content of this article. I hope that the content of this article has certain reference and learning value for everyone’s study or work. Thank you for your support.

Related Posts

Alibaba Cloud server construction and Pagoda panel installation (graphic tutorial)

The first Qt program I ran on a Linux development board

[Linux] Common instructions (2)

Step-by-step tutorial on writing automated installation scripts for Oracle11g under Linux

VMware virtual machine installs the original MAC OS system and easily experiences the Apple operating system

Detailed explanation of HAProxy restart mechanism

Metasploitable-linux-2.0.0 target machine download and configuration tutorial

[Linux Ladder] Chapter 2 · Linux system environment setup

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*