How to Diagnose Slow OpenAPI Responses with TProfiler Java Agent

This article walks through diagnosing intermittent OpenAPI latency by using Alibaba's open‑source TProfiler Java agent to collect method‑level timing without modifying code, covering setup, command‑line usage, log analysis, and practical performance‑improvement recommendations.

dbaplus Community
dbaplus Community
dbaplus Community
How to Diagnose Slow OpenAPI Responses with TProfiler Java Agent

Problem

OpenAPI service latency varies from tens of milliseconds to several seconds. The issue cannot be reproduced in a fast test environment, making traditional per‑method logging impractical.

Solution: TProfiler Java Agent

Alibaba’s open‑source TProfiler Java agent records method execution times without modifying source code. Adding the agent at JVM startup with a properties file incurs minimal performance overhead.

Setup

Clone the repository and build the jar:

git clone https://github.com/crossoverJie/TProfiler
mvn assembly:assembly

The compiled jar is located at TProfiler/pkg/TProfiler/lib/tprofiler-1.0.1.jar.

Create a profile.properties file that configures the profiling port and other options (example shown in the image).

Start the target application with the agent and the properties file:

-javaagent:/TProfiler/lib/tprofiler-1.0.1.jar -Dprofile.properties=/TProfiler/profile.properties

Demo Application

A simple HTTP endpoint built with cicada invokes two time‑consuming methods. While the service runs, TProfiler writes raw samples to tprofile.log.

Flushing Samples

Because tmethod.log is initially empty, run the client to flush the latest samples:

java -cp /TProfiler/tprofiler.jar com.taobao.profile.client.TProfilerClient 127.0.0.1 50000 flushmethod

The command contacts the profiling service, parses tprofile.log, and writes aggregated method data to tmethod.log.

Computing Average Latencies

Run the analysis tool to generate per‑method statistics:

java -cp /TProfiler/tprofiler.jar com.taobao.profile.analysis.ProfilerLogAnalysis tprofiler.log tmethod.log topmethod.log topobject.log

The resulting topmethod.log lists, for each method, the request count, average latency, and total time. Example entry: request count 4, average 205 ms, total 818 ms.

Inspecting Individual Invocations

Locate the method ID in tmethod.log (e.g., method selectDB has ID 2) and grep that ID in tprofiler.log to view each execution’s timestamp and duration:

grep 2 tprofiler.log

Findings and Recommendations

The slowest methods are all database‑related, indicating high DB load.

Mitigation strategies include hot‑cold data separation, sharding, and converting some write‑to‑DB operations to asynchronous processing.

For deeper visibility, consider adopting a distributed tracing system such as Pinpoint.

Key Advantages of TProfiler

TProfiler offers lightweight, zero‑code‑change profiling that can be extended with custom dashboards, making it suitable for rapid incident investigation.

TProfiler configuration file
TProfiler configuration file
Sample HTTP endpoint
Sample HTTP endpoint
Top method latency summary
Top method latency summary
Method ID grep result
Method ID grep result
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backendperformance profilingJava AgentOpenAPItprofiler
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

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.