Backend Development 9 min read

Diagnosing SpringBoot Service Latency with Arthas and JMeter Simulation

This article explains how to reproduce a slow‑response SpringBoot service using JMeter, then quickly locate the bottleneck in production by leveraging Alibaba's open‑source Arthas tool and its trace command to analyze the full call chain.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Diagnosing SpringBoot Service Latency with Arthas and JMeter Simulation

Preface

Recently an online service interface exhibited a long response time, resulting in a poor user experience. How can such problems be investigated quickly?

1. Adding detailed logging is not recommended because the production environment cannot be redeployed easily and extensive logs would consume large disk space.

2. Building a replica testing environment for root‑cause analysis is also not recommended as it is time‑consuming.

3. The recommended solution is the online diagnostic tool Arthas , an open‑source utility from Alibaba that provides many commands for troubleshooting. When a response‑time issue occurs, the trace command can be used to collect performance costs along the entire call chain and identify the slow methods.

The article proceeds in two parts:

Setting up a simulated environment where a SpringBoot service interface has an artificially long response time, using JMeter to invoke the service.

Using Arthas's trace command to diagnose the latency issue.

Simulating the Online Environment

1. Create a SpringBoot project and implement the service interface.

Note: The service code contains only some heavy loops to simulate long execution time. In real scenarios, other common causes include: ① Heavy JDBC operations with large data sets and missing indexes, leading to slow queries. ② Calls to other services that themselves are slow, propagating latency to the current interface.

The service interface code is shown in the following image:

Methods test1 and test2 are illustrated below:

2. Configure a JMeter test script to simulate user calls.

3. Project structure containing the SpringBoot service code and JMeter script:

After preparing the service code, export it as a JAR using the IDEA IDE. The code and JMeter script can be downloaded from: https://github.com/leishen6/springboot_arthas

Deploy the JAR to a server and start it with java -jar <jar-file>.jar . Then run JMeter to invoke the interface and observe the average response time in the aggregate report (see image).

If users report a slow feature, follow the steps below to quickly locate the cause.

Arthas Troubleshooting

1. Download the Arthas diagnostic tool JAR from https://arthas.aliyun.com/arthas-boot.jar and place it on the same server as the service.

2. Use the ps command to find the process ID of the running service JAR, e.g.:

ps -ef | grep springboot_arthas-1.0.0.jar

3. Launch Arthas with:

java -jar arthas-boot.jar

Select the target Java process by entering its index (e.g., [1] ).

4. Use the trace command to monitor the execution time of methods called by the service interface.

trace searches for the specified class‑pattern / method‑pattern and renders the full call chain with performance statistics.

Command format: trace [full‑qualified‑class-name] [method‑name]

Example – monitor the service interface method:

Class: com.lyl.controller.TestController , Method: process

Actual command:

trace com.lyl.controller.TestController process

5. The trace result is displayed as shown below:

The trace reveals that the method test2() in com.lyl.util.StringUtil consumes a large amount of time, indicating that its implementation should be examined. If further nested calls exist, repeat the trace to pinpoint the exact bottleneck.

Arthas provides many other commands; refer to the documentation at https://arthas.aliyun.com/doc/commands.html .

Note: ① The program being diagnosed must not be obfuscated; otherwise the trace command will report "class or method not found". ② The JMeter script must be running while executing the trace command; otherwise no call‑chain data will be collected.

Source: https://juejin.im/post/6880479570894520333

JMeterSpringBootArthasTracePerformance Debugging
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.