Video in progress
p99 latency has occasional 500 ms spikes. How do you prove whether or not they are caused by GC?
I overlay the timestamps of the spikes with the pauses in the GC and safepoint logs. If they match, it's GC. If not, I check in JFR what the threads were waiting on at that moment, and check DB, network and CPU throttling.
📖 Answer
The assumption "it got slow, so it's GC" often turns out wrong. I close this out with evidence.
- From the latency graph I take the exact times of the spikes (millisecond precision, in the same time zone).
- I look at the GC log with the
uptimeandtimedecorators on:
-Xlog:gc*,safepoint:file=gc.log:time,uptime,level,tags
If there is a 400-500 ms Pause or a long safepoint at the time of the spike, found it.
3. If there is nothing in the GC, I look at the JFR recording for that interval: jdk.ThreadPark, jdk.SocketRead, jdk.JavaMonitorEnter events, to see what the threads were waiting for.
4. CPU throttling at the container level: container_cpu_cfs_throttled_periods_total. If the CPU limit in Kubernetes is hard, both the GC threads and the application stop until the end of the 100 ms period. This can show up as a "long pause" in the GC log, or not at all.
5. At the host level: swap, a slow disk (writing the GC log synchronously to a slow disk causes pauses too!), transparent huge pages.
One useful tool is jHiccup or a similar approach: a background thread inside the application sleeps 1 ms at a time and measures how long it really slept. If the "hiccups" it sees don't match the GC log, the cause is outside the JVM.
The result is always stated with numbers: "80% of the spikes match G1 mixed pauses, 20% match throttling".
Sign up to mark studied questions and save your progress.