Video in progress

In prod, one endpoint's p99 latency went from 200 ms to 3 seconds, while the average barely changed. How do you investigate?

First I establish the scale of the problem from metrics: which endpoint, which pod, since when, and what happened at the same time. Then I open traces of the slow requests to see where the time went, and finally move to those traces' logs. The fact that the average didn't change shows the problem affects a small number of requests.

📖 Answer

If the average stays put while p99 grew, it's not "everything is slow", it's that a certain share of requests is very slow. I narrow down to that.

  1. When, and what coincided. On the graph I find the start time and compare it with deploys, config changes and traffic growth. Grafana annotations help a lot here.

  2. Where. I split by by (instance): one pod or all of them? If it's one pod, that node, GC or a "noisy neighbor" may be the cause. Then I split by by (uri, status): maybe only requests that came with certain parameters are slow.

  3. Resources (USE). I look for what changed at the same time:

    • hikaricp_connections_pending > 0: the pool is exhausted;
    • jvm_gc_pause_seconds_max: long GC pauses;
    • whether Tomcat's busy threads have hit the max;
    • the latency of the downstream service's http.client.requests.
  4. Traces. In Tempo or Jaeger I search with the filter duration > 2s. Often the answer shows up right here: for example, if there are "gaps" between spans, the code is waiting for something (a lock, a pool); if there is a long JDBC span, the SQL is slow.

  5. Logs. I open the logs by the traceId of the trace I found: retries, timeouts, warnings.

Causes usually found: a big dataset for a particular customer (N+1 queries, a 10,000-row order), a new query that isn't using an index, an external API timeout and retry, connection pool exhaustion, a full GC.

If traces and metrics aren't enough, I take a thread dump from the problem pod (jcmd <pid> Thread.print) or attach async-profiler for a minute.

At the end I answer two questions: why didn't an alert catch this earlier, and which metric was missing to prevent this from happening again.