Performance testing: load, stress, spike, soak and coordinated omission
Load, stress, spike, soak and capacity tests told apart; goals derived from SLOs; open versus closed workload models, arrival rate, think time; coordinated omission measured with a JDK 21 experiment (p99 of 2.6 ms becomes 975 ms); throughput, percentiles, USE/RED; k6 and Gatling Java DSL scripts; data, warm-up, finding the bottleneck, reporting results, and when to use JMH.
On this page
1. The problem
A load test with 100 virtual users reports p99 of 3 ms, and the team signs off. Three weeks later, every 1-second GC pause makes users wait up to a second. The tool waited for each response before sending the next, so it never sent anything while the server was frozen.
2. Key idea
Like testing a bridge: load runs rush-hour traffic, stress piles on until it cracks, spike pours cars on at once, soak runs for a week to find metal fatigue, capacity finds the safe maximum. Good stress behaviour is failing gracefully: return 503 fast, then recover.
A proper target: "p99 < 300 ms at 450 req/s (peak 300 × 1.5) for 30 minutes, errors < 0.1%", with a production-like request mix, written into the script so the pipeline fails on its own.
2.1 Open or closed model?
Closed: N virtual users send, wait for the response, pause, send again. Throughput = N / (response + think time): 100 users, 1 s think, 0.1 s response is ~91 req/s; at 2 s response it drops to 33 req/s. The tool backs off exactly when the server is weak. Open: requests arrive on a fixed schedule regardless of the server, like Internet users.
| Model | Use when | Don't use when |
|---|---|---|
Open (constant-arrival-rate, injectOpen) |
public APIs, Internet traffic | fixed clients that wait on each other |
| Closed | a fixed number of clients: workers, batch jobs | you want to see behaviour under overload |
2.2 Coordinated omission
A JDK 21 experiment: ~1 ms per request, the server stalls 1 second every 5; 200 req/s for 20 seconds.
| Measurement (ms) | avg | p99 | max |
|---|---|---|---|
| Closed, from actual send | 2.76 | 2.63 | 1,007 |
| Closed, from intended send | 147.6 | 974.7 | 1,007 |
| Open (virtual threads) | 106.8 | 956.9 | 1,011 |
The first method records only one slow sample per stall (~0.1% of samples). The fix: measure latency from the intended send time, or use an open model.
3. A sample script (k6)
export const options = {
scenarios: {
peak: {
executor: 'constant-arrival-rate', // open model
rate: 450, timeUnit: '1s', duration: '30m',
preAllocatedVUs: 200, maxVUs: 1000, // too few VUs and iterations get dropped
},
},
thresholds: {
http_req_failed: ['rate<0.001'],
'http_req_duration{name:listProducts}': ['p(95)<150', 'p(99)<300'],
dropped_iterations: ['count<1'], // the target load was really generated
},
};
export default function () {
const page = Math.floor(Math.random() * 50); // random ids, not one page over and over
http.get(`${__ENV.BASE_URL}/products?page=${page}`, { tags: { name: 'listProducts' } });
}Gatling (injectOpen) suits Java teams; JMeter defaults to a closed model. The environment must match production: CPU limits, pod count, a real-sized DB.
What to measure and how to find the bottleneck
- RED per endpoint: Rate, Errors (including client-side timeouts), Duration. USE per resource: Utilization, Saturation (work waiting), Errors. Response time ≈ service time / (1 − utilization): 80% busy is 5x, 90% is 10x.
- Don't average p99 over 10 pods: merge histograms first (
histogram_quantileover summed buckets, MicrometerpublishPercentileHistogram). - Little's law L = λ × W: 400 req/s × 50 ms = 20 requests in flight; 200 threads always busy means the numbers contradict each other.
- Bottlenecks: low CPU with threads waiting in
getConnectionis an exhausted DB pool; latency creeping up in a soak is GC or a leak; manyBLOCKEDthreads is a lock; low average CPU with high p99 is CPU-limit throttling (nr_throttled). - The load generator can be the bottleneck: the server is idle, k6 reports
dropped_iterations. Run it on its own machine and watch its CPU. - JMH measures one function in one JVM; load tests measure the whole system. Different questions.
4. Working with AI
Delegate to AI: k6/Gatling scripts from OpenAPI, data feeders, reading reports and thread dumps.
Check yourself:
- The executor is an open model (
constant-arrival-rate,injectOpen), notvus+duration, for public APIs. - Thresholds come from the SLO, plus
dropped_iterations. - Ids come randomly from a production-sized feeder, not one repeated id.
- The report states the environment, load steps, p99, errors and the first saturated resource.
5. Exercises
Exercise 1: A closed model backs off
A closed-model tool: 50 virtual users, 1 s think time, 200 ms normal response, 2 s during an incident. What throughput does the tool generate before and during the incident? What does production (open, 40 req/s) see?
Solution to Exercise 1
- Before: 50 / (0.2 + 1) ≈ 41.7 req/s. During: 50 / (2 + 1) ≈ 16.7 req/s: the tool cuts its load by 60% exactly when the server is weak.
- Production: users keep arriving at 40 req/s. If the server is slow because it's overloaded, it can't keep up, the queue grows until timeouts, and client retries add more load. If it holds at 2 s, Little's law gives 80 requests waiting.
- Lesson: overload behaviour only shows up with an open model.
Exercise 2: Review a "p99 4 ms, passed" report
AI ran a JMeter Thread Group of 200 threads, 10 s ramp, loop forever, on a 1-pod staging with a 10,000-row DB, every request using productId=1, and concluded "p99 4 ms, meets the 300 ms SLO at 450 req/s". List why you can't trust it.
Solution to Exercise 2
- Closed model: it doesn't prove 450 req/s arrived on schedule, and it's prone to coordinated omission.
- Data: 10,000 rows and one
productIdfit entirely in cache; production has millions of rows with skewed access. - Environment: 1 pod, unlike production's pod count, CPU limits and pools.
- Missing: the request mix, error rate, saturated resources, a 30-minute hold, warm-up.
- Redo it: an open model at 450 req/s, a random-id feeder, a production-sized environment, self-failing thresholds.
Summary
- Pick the test type by the question: load, stress, spike, soak, capacity.
- Targets are numbers from the SLO, written as self-failing thresholds.
- Real users are an open model; closed models hide overload.
- Coordinated omission fakes a good p99; measure from the intended send time.
- Merge histograms before computing p99; find the first saturated resource.
Further reading: Back-of-the-envelope estimation.
Self-compiled notes from official documentation and hands-on practice.
Comments
Community rules