Video in progress
In a load test the service works fine up to 800 RPS, and after that latency shoots up and throughput stops growing. Which metrics do you use to find the bottleneck?
This is a sign of saturation: some resource is 100% busy and a queue is building in front of it. I put utilization and saturation for each resource (CPU and throttling, Tomcat threads, Hikari pending, executor queue, GC time, downstream latency) on one graph next to the load and find the resource that saturates first. Little's law helps check which pool is too small.
📖 Answer
The "elbow" shape of latency is classic queueing theory: until a resource saturates there is almost no waiting, and after it saturates the queue grows without bound. The job is to find which resource saturated first. I run the load test in steps (200, 400, 600, 800, 1000 RPS, 5 minutes each) and record the following for each step:
| Resource | Utilization | Saturation |
|---|---|---|
| CPU | process_cpu_usage |
container_cpu_cfs_throttled_periods_total |
| Tomcat | tomcat_threads_busy_threads / config_max |
waiting connections, accept queue |
| DB pool | hikaricp_connections_active / max |
hikaricp_connections_pending, acquire time |
| GC | rate(jvm_gc_pause_seconds_sum[1m]) |
allocation rate, old gen filling up |
| Downstream | http_client_requests rate |
its p99 and timeouts |
The first row that hits the elbow is the bottleneck. For example, CPU is at 45%, but hikaricp_connections_pending jumps from 0 to 60 at 800 RPS: it's the pool.
A check with Little's law: required parallel connections ≈ throughput × the time each request holds a connection. 800 RPS × 25 ms = 20 connections. If the pool is 20, it saturates right there. But before making the pool bigger I ask: can the DB take it? Often the right fix is to shorten the time a connection is held (move the external call out of the transaction, speed up the query).
If CPU is the bottleneck, the next step is profiling: a flame graph with async-profiler, which usually points at serialization, log formatting or a regex. If there is throttling, I check the CPU limit and the number of GC threads.
One note: the load generator itself can be the bottleneck. The generator machine's CPU, and a tool that doesn't account for "coordinated omission", hide latency. So I compare the result with the server-side histogram.
Sign up to mark studied questions and save your progress.