A checkout API on a JVM went from about 120 ms to 260 ms p99 after a release, while p50 and errors stayed flat; how do you split the extra tail time by cause?
answer
- a minority of requests pay
- stops before CPU before waiting
- pauses, safepoints, on-CPU, off-CPU, downstream
- line slow requests up in time
- one instrument per hypothesis
basics
~20 sAttribute the extra tail time to JVM stops (GC pauses and time-to-safepoint), on-CPU work, off-CPU waiting on locks, pools or I/O, or slower downstream calls, reading the always-on logs first and adding one targeted recording per surviving hypothesis.
solid answer
~40 sA flat p50 means a minority of requests pay the extra time, so I look for something intermittent or load-dependent. First the evidence already on: GC and `-Xlog:safepoint` logs. Do stops line up in time with the slow requests, and are they about 140 ms long? Then CPU: is the process near its limit or throttled, and did CPU per request rise? If stops and CPU do not account for it, the time is off-CPU, so a short JFR recording shows monitor waits (`jdk.JavaMonitorEnter`), parks (`jdk.ThreadPark`) and socket reads (`jdk.SocketRead`) with stacks, and per-dependency client timings show whether a downstream slowed. Each hypothesis gets the one instrument that confirms or kills it, and I change nothing until one does.
code
bash · 5 lines# always-on, set at startup: GC and safepoint logging to a rotated file
java -Xlog:gc*,safepoint:file=/var/log/app/jvm.log:time,uptime,level,tags:filecount=5,filesize=20m -jar checkout.jar
# during a slow window: a short, richer JFR recording on the instance that regressed
jcmd <pid> JFR.start name=p99 settings=profile duration=5m filename=/var/log/app/p99.jfrgo deeper
Recall that a JVM can stop all application threads, that requests can wait on locks, pools and other services, and that each of these shows up in a different piece of evidence.
Explain the five places tail time hides and which recorded evidence speaks to each: GC and safepoint logs, CPU and throttling, JFR wait events, dependency timings.
Demonstrate the order: read the p50-flat shape, check the cheap always-on evidence and line it up in time and magnitude, then add exactly one targeted instrument per surviving hypothesis.
Discuss making this triage fast for every team: the evidence each JVM records by default, consistent dependency timings, and a written order of checks that on-call follows before anyone changes a flag.
## Read the shape first The checkout API's p99 went from about **120 ms to about 260 ms** after a release, while **p50 and the error rate stayed flat**. Before choosing an instrument, read what that shape says: most requests are as fast as before, so the extra 140 ms is paid by a minority. Causes that hit a minority of requests are usually **intermittent** (a pause that stalls everything in flight for its duration), **load-dependent** (queueing at peaks), or **path-dependent** (one route, one dependency, one input shape). A uniform slowdown of every request would normally have moved the median as well. The playbook below assumes the measurement has already been checked (same percentile, same load and mix) and the changes have been listed. Its job is to **attribute the extra tail time** to one of five places, testing each with the cheapest evidence that can confirm or rule it out. ## The five places tail time hides | Place | What it looks like in the tail | Evidence that discriminates | Cost | |---|---|---|---| | **GC pauses** | slow requests cluster inside collection pauses | GC log (`-Xlog:gc*`), JFR `jdk.GarbageCollection` and `jdk.GCPhasePause` | already on, near zero | | **Time-to-safepoint and non-GC stops** | stopped time well beyond GC pause totals | `-Xlog:safepoint`, which separates reaching the safepoint from time spent at it; JFR `jdk.SafepointBegin` | already on, near zero | | **On-CPU work** | more CPU per request, or the process at its CPU limit or throttled | process CPU against the limit, container throttling counters, a CPU profile (JFR `jdk.ExecutionSample`, async-profiler `-e cpu`) | low, short window | | **Off-CPU waiting** | threads blocked on monitors, parked on a pool or lock, waiting in socket reads | JFR `jdk.JavaMonitorEnter`, `jdk.ThreadPark`, `jdk.SocketRead` with stack traces; async-profiler `-e wall` or `-e lock`; a series of thread dumps | low to moderate | | **Downstream calls** | one dependency's client-side latency rose | per-dependency client timings, distributed traces | already on if instrumented | A JVM **stop** (a GC pause or any other safepoint operation) stops every thread running Java code, so a request in flight during it is stretched by up to the stop's length. That is why stops are checked first: they are cheap to read, already recorded on a well-run JVM, and a classic cause of a tail-only regression. ## The order of checks 1. **Line up stops with slow requests.** From the GC and safepoint logs, take the stop durations per minute and compare them in time with the slow requests. If the 260 ms requests sit inside stops of roughly 140 ms, you have found the place; why the stops grew (more allocation, a different collector, a slow safepoint) is the next, narrower question. 2. **Check CPU before profiling.** Is the process near its CPU limit, or is the container being throttled? A pod moved to a new node pool may get less CPU per period than before. Throttling stretches tails while average CPU looks fine. 3. **If stops and CPU do not explain it, look off-CPU.** A short JFR recording with the `profile` settings shows where threads wait, with stack traces; a wall-clock profile shows the same from the sampling side. 4. **Check the downstreams.** Compare each dependency's client-side latency before and after; a slower call on one route explains a minority-only regression neatly. 5. **Only then form a fix**, and change one thing. ## Correlating in time - Align timestamps across sources: request logs, GC and safepoint logs, JFR events and dependency metrics should all be read on the same clock and the same window. - Check **magnitude** as well as coincidence: a stop explains a slow request only if it is about as long as the extra time. - Watch the **direction of causation**: if pauses grew because the release allocates more per request, the root cause is the code change, and the allocation rate before and after shows it. - Check **per instance**: a cause on a few pods will not show in fleet-wide sums. ## What this playbook does not do - It names the next instrument; it does not teach reading it. Reading individual GC log lines, safepoint log fields, flame graphs and thread-dump patterns each belongs to its own subject. - It does not start with flags. A flag change before the evidence names a cause turns one unknown into two.
- The safepoint log shows stops during slow minutes that add up to far more than the GC log's pauses. What next?That points at time-to-safepoint or non-GC VM operations rather than collection work, so GC tuning is the wrong lever. The next instrument is the safepoint evidence itself: which operations stopped the world and which thread was late to arrive. First confirm those stops coincide with the slow requests and match the extra time; then hand over to a safepoint-stall diagnosis.
- Neither stops nor CPU explain it, and a CPU profile looks the same as last week's. Why?A CPU profile samples threads that are running, so time a request spends blocked on a monitor, parked waiting for a pool connection or sitting in a socket read does not appear in it. Switch to off-CPU evidence: JFR's monitor, park and socket events with stack traces, an async-profiler wall-clock or lock profile, and per-dependency client latency.
- Slow requests coincide with longer GC pauses. How do you avoid fixing the symptom?Ask why the pauses grew. If the release allocates more per request, the allocation rate in the GC log or JFR rose with it, and the root cause is the code, not the collector settings. Compare allocation and promotion before and after the release before touching any GC flag.
- Changes GC flags before any evidence points at GC.
- Reads only a CPU profile and concludes nothing changed.
- Treats GC pause time as all of the JVM's stopped time.
- Compares average latency, which hides a tail-only regression.
- Turns on every profiler at once instead of testing one hypothesis.