How to Use Arthas monitor to Track Java Method Performance and Latency
This article explains how the open‑source Java diagnostic tool Arthas can monitor method execution with the monitor command, describes each monitoring metric, shows how to configure the sampling interval, and demonstrates the impact on response time using a concrete code example.
What is Arthas?
Arthas is an open‑source Java diagnostic utility that provides real‑time insight into running JVM processes. It offers commands for class inspection, thread analysis, and performance monitoring without requiring application restarts.
Key Command: monitor
The monitor command focuses on tracking the execution of a specific Java method. It periodically records a set of metrics that help you understand how often the method is called, how many calls succeed or fail, and how long each call takes.
Monitoring Metrics
timestamp : The time when the record was taken.
class : Fully qualified Java class name.
method : Method name (including constructors).
total : Total number of invocations.
success : Number of successful executions.
fail : Number of failed executions (exceptions are counted as failures).
rt : Average response time (in milliseconds) of the method.
fail‑rate : Percentage of failed calls.
Among these, the rt (average response time) is especially useful for spotting performance regressions under different input parameters.
Command Options
The command accepts a single option -c that defines the sampling period. If omitted, the default interval is 120s. Longer intervals reduce overhead but provide coarser data.
Performance Impact
Running monitor does introduce some overhead. In a simple experiment, enabling the command increased the average response time of the target method by roughly 50 %. Once Arthas is detached, the JVM returns to its original performance levels.
Example Code
package com.fun;
import com.fun.frame.httpclient.FanLibrary;
import com.fun.utils.Time;
public class AR extends FanLibrary {
public static void main(String[] args) {
while (true) {
sleep(1000);
long mark = Time.getTimeStamp();
for (int i = 0; i < 1000; i++) {
output(DEFAULT_STRING);
}
long mark1 = Time.getTimeStamp();
System.out.println(mark1 - mark);
}
}
static String test() {
sleep(100);
return DEFAULT_STRING;
}
String fun() {
sleep(100);
int randomInt = getRandomInt(2);
if (randomInt == 1) fail();
return DEFAULT_STRING;
}
}When the above program runs, you can attach Arthas and execute monitor com.fun.AR fun -c 30 to observe the metrics listed earlier.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
