Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of high CPU occupancy rate of online servers and how to solve the problem of location?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to solve the problem of how to solve the high occupancy rate of online server CPU and how to troubleshoot and locate the problem. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.

Positioning process

Log in to the server, execute the top command, and check the CPU usage:

$top

PID USER PR NI VIRT RES SHR S CPU MEM TIME+ COMMAND

1893 admin 20 0 7127m 2.6g 38m S 181.7 32.6 10:20.26 java

Top command is a commonly used performance analysis tool under Linux, which can display the resource consumption of each process in the system in real time, similar to the task manager of Windows.

Through the above command, we can see that the CPU occupancy rate of the Java process with a process ID of 1893 has reached 181%. It can basically be located that our Java application caused the CPU occupancy rate of the entire server to soar.

Locate thread

We know that Java is single-process and multithreaded, so let's take a look at the CPU usage of each thread in the Java process of PID=1893, again with the top command:

$top-Hp 1893

PID USER PR NI VIRT RES SHR S CPU MEM TIME+ COMMAND

4519 admin 20 0 7127m 2.6g 38m R 18.6 32.6 0:40.11 java

Through the top-Hp 1893 command, we can find that among the current 1893 processes, threads with an ID of 4519 occupy the highest CPU.

Location code

With the top command, we've located the specific thread that caused the high CPU usage, so let's find out which line of code has the problem.

First, we need to convert the 4519 thread to hexadecimal:

$printf x 4519

11a7

Next, use the jstack command to view the stack information:

$sudo-u admin jstack 1893 | grep-A 200 11a7

"HSFBizProcessor-DEFAULT-8-thread-5" # 500 daemon prio=10 os_prio=0 tid=0x00007f632314a800 nid=0x11a2 runnable [0x000000005442a000]

Java.lang.Thread.State: RUNNABLE

At sun.misc.URLClassPath$Loader.findResource (URLClassPath.java:684)

At sun.misc.URLClassPath.findResource (URLClassPath.java:188)

At java.net.URLClassLoader$2.run (URLClassLoader.java:569)

At java.net.URLClassLoader$2.run (URLClassLoader.java:567)

At java.security.AccessController.doPrivileged (Native Method)

At java.net.URLClassLoader.findResource (URLClassLoader.java:566)

At java.lang.ClassLoader.getResource (ClassLoader.java:1093)

At java.net.URLClassLoader.getResourceAsStream (URLClassLoader.java:232)

At org.hibernate.validator.internal.xml.ValidationXmlParser.getInputStreamForPath (ValidationXmlParser.java:248)

At org.hibernate.validator.internal.xml.ValidationXmlParser.getValidationConfig (ValidationXmlParser.java:191)

At org.hibernate.validator.internal.xml.ValidationXmlParser.parseValidationXml (ValidationXmlParser.java:65)

At org.hibernate.validator.internal.engine.ConfigurationImpl.parseValidationXml (ConfigurationImpl.java:287)

At org.hibernate.validator.internal.engine.ConfigurationImpl.buildValidatorFactory (ConfigurationImpl.java:174)

At javax.validation.Validation.buildDefaultValidatorFactory (Validation.java:111)

At com.test.common.util.BeanValidator.validate (BeanValidator.java:30)

From the above code, we can clearly see that there may be a problem with line 30 of BeanValidator.java.

three

Problem solving

The next step is to solve the problem by looking at the code. We found that we customized a BeanValidator, encapsulated Hibernate's Validator, and then initialized a Validator instance through Validation.buildDefaultValidatorFactory (). GetValidator () in the validate method. Through analysis, we found that this instantiation process is time-consuming.

We refactored the code to bring the initialization of the Validator instance out of the method, and creating it once at the time of class initialization solved the problem.

four

Summary

The above shows the online problem location process completed by a comparison. The main commands used are: top, printf and jstack

In addition, you can also use Alibaba's open source tool Arthas to troubleshoot online problems. You can use the following command to locate the above problems:

Thread-n 3 / / View cpu accounts for the top three threads

The above is how to solve the online server CPU occupancy rate is high and how to troubleshoot the location problem, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report