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 troubleshoot the long response time of online services

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the knowledge of "how to troubleshoot the problem that the response time of online service is too long". Many people will encounter such a dilemma in the operation of actual cases. next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Foreword:

Recently, the response time of an interface service in the online environment is too long, resulting in a poor sense of user experience. When this happens, how can we quickly troubleshoot such problems?

Common troubleshooting ideas:

Add a detailed print log to the code; it is not recommended that you cannot easily redeploy the code that has changed the detailed log in the online environment, and add detailed log output, which means that a large number of log files will be generated. These log files will take up a lot of server disk space.

Build a test environment that simulates an online environment for review and troubleshooting; well, there is not so much time for you to conduct an environmental review when this problem arises, so this solution is not recommended.

Online diagnostic artifact Arthas, this tool is open source by Ali, specifically for online environmental problems troubleshooting, this tool provides a lot of commands to troubleshoot problems When the above response time is too long, you can use the trace command provided by Arthas to troubleshoot. The trace command using this tool can count all the performance overhead on the entire call link in the method and track the call link. You can find the more time-consuming methods and then troubleshoot them.

Next, the article will be carried out from two aspects:

①, build an environment that simulates the long response time of online service interface; SpringBoot service interface + JMeter simulation service interface invocation

②, use the command trace command provided by the diagnostic artifact Arthas to troubleshoot problems with long response time

Simulate the online service environment:

1. Build the SpringBoot project and write the service interface

Note: the service interface code is only written in large loops to simulate long time-consuming code for simplicity; in addition, it actually contains many other common situations, such as:

There are a lot of JDBC operations in the service interface method, and because the amount of data in the database is too large, many JDBC queries are very time-consuming, and at this time, the query time may be longer because the appropriate index has not been created, resulting in a longer response time of the service interface.

Other service interfaces are called in this service interface, which takes a long time to execute due to problems with other service interfaces invoked internally, which leads to a long response time of the service interface.

The service interface code is as follows:

2. JMeter simulates the configuration of the test script called by the user:

Once the service interface code is ready, export it as a Jar package using the IDEA development tool.

Service interface code and JMeter script to obtain address: simulate Demo source code address

To simulate the most real online environment, put the prepared service interface Jar package into the Linux server, and then run the Jar package with the command java-jar .jar

Finally, JMeter is used to call the interface, and the aPCge response time is found to be too long in the aggregation report, as shown in the figure:

Arthas troubleshoots problems:

Follow the steps below, and you will find out the cause of the problem successfully and quickly.

1. First, you need to download the Jar package of Ali's open source Arthas diagnostic tool at arthas-boot.jar, and then put the Jar package in the server where the service interface project is deployed.

2. Then use the ps command to query the process number of the program running the service interface; for example: the name of the service interface program Jar package simulated in this article is springboot_arthas-1.0.0.jar, so the command is: ps-ef | grep springboot_arthas-1.0.0.

3. Then run the Arthas diagnostic tool with the command: java-jar arthas-boot.jar. The interface that starts running is shown in the figure:

4. After running, you can use the trace command to count the time it takes to call all nodes on the link using the service interface method.

The trace command can actively search the method call path corresponding to class-pattern/method-pattern, render and count all the performance overhead on the entire call link and track the call link.

Specific command format: trace [fully qualified class name] [method name in the class]

For example, the API of this service for statistics:

Com.lyl.controller.TestController: fully qualified class name

Methods in the process:TestController class

Specific command: trace com.lyl.controller.TestController process

5. The execution result of trace command is shown, as shown in the figure:

The execution time of each method in the calling link is monitored by the trace command, and it can be found that the execution of the test2 () method in the called com.lyl.util.StringUtil class takes a lot of time.

So you need to specifically check whether there is a problem with the code of this method.

If there are still a lot of method call links in this code, you need to use the trace command again to monitor the time-consuming of the calling link to find out the specific methods that may have problems.

Arthas Ali open source diagnostic tool also provides a lot of commands to use, you can check to learn, address: command list.

Note:

①, the program code that uses Arthas diagnosis should not be confused when packaging, otherwise the class or method will not be found when using the trace command.

②. When using the trace command to monitor statistics, it is required that the JMeter test script is running to call the service interface. If the service interface is not being called, the time spent on the internal calling link cannot be counted.

This is the end of the content of "how to troubleshoot online service response time is too long". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Development

Wechat

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

12
Report