Backend Development 14 min read

Resolving a 100 ms Latency Issue in Spring Boot’s Embedded Tomcat Using Arthas Tracing

The article details a step‑by‑step investigation of an unexpected ~100 ms latency in a Spring Boot‑based channel system, covering network checks, curl measurements, Arthas trace and watch commands, identification of TomcatJarInputStream’s repeated jar‑resource loading caused by Swagger dependencies, and the final fix by upgrading the embedded Tomcat version.

Architect
Architect
Architect
Resolving a 100 ms Latency Issue in Spring Boot’s Embedded Tomcat Using Arthas Tracing

Background

The author maintains a channel system built with Spring Boot and embedded Tomcat, which simply forwards requests to third‑party channels. After code optimizations the response time was still ~100 ms slower than expected, with the caller seeing ~250 ms while internal logs reported ~150 ms.

Diagnosis Process

1. Network verification : ping tests from the client to the Nginx host and from Nginx to the channel server showed sub‑millisecond latency, ruling out network issues.

2. Direct localhost request using curl -w "@curl-time.txt" http://127.0.0.1:7744/send revealed a consistent 73 ms cost on the first call and ~3 ms on the second, indicating a caching effect.

3. Spring MVC analysis : No special filters or interceptors were found, so the problem was not in business logic.

Using Arthas for Deep Tracing

The author employed Arthas, Alibaba’s Java diagnostic tool, focusing on the trace command to locate the time‑consuming method. Initial trace of Spring MVC showed only 18 ms, leaving ~97 ms unaccounted for.

Further tracing of the Tomcat request processor ( org.apache.coyote.http11.Http11Processor.service ) exposed a 129 ms hotspot.

Detailed trace of org.apache.catalina.webresources.TomcatJarInputStream.createZipEntry showed 31 invocations consuming a total of ~74 ms, caused by repeated loading of META‑INF resources from JAR files.

Root Cause

The repeated loading was triggered by the Swagger UI libraries ( springfox-swagger2 and springfox-swagger-ui ) packaged in the application. Removing these dependencies eliminated the extra latency.

Solution

Upgrade the embedded Tomcat version (e.g., from 8.5.31 to 8.5.40 or later) which contains a fix for the bug, or simply upgrade Spring Boot to a version that bundles a newer Tomcat.

For Maven projects, the fix can be applied by overriding the Tomcat version in pom.xml :

<properties>
    <tomcat.version>8.5.40</tomcat.version>
</properties>

Alternatively, upgrade the Spring Boot parent version to 2.1.0.RELEASE or newer.

Conclusion

The latency was not a code‑level issue but a Tomcat‑embed bug triggered by Swagger’s static resources; upgrading Tomcat resolves the problem and restores expected response times.

backendJavaperformanceSpring BootTomcatArthasSwagger
Architect
Written by

Architect

Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.

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.