A load test in practice: SLO, data, conclusions
A load test gives a decision-ready result only when the goal (SLI and SLO) and a baseline are set first. Then it needs a realistic scenario with varied data, warm-up with ramp-up, and analysis. Without an SLO a p95 figure means nothing, and one account and one endpoint leave the work to the cache. Percentiles, errors and server metrics reveal the bottleneck, and repeated runs show the spread.
API · Load
A test showed p95 = 400 ms. Is that good or bad, and can you trust it?
The test ran, k6 printed a nice table, and p95 is 400 ms. Without a criterion it is unclear whether that is a success. If every request in the test used one account, the data landed in the cache and the number means nothing at all. A load test without goals, a baseline and realistic data produces only pretty graphs. This lesson is about an order of work that makes the result fit for a decision.
How it works
The work goes in five steps, and each one guards against a particular false conclusion.
The order of a load test
1. Goals. An SLI (service level indicator) is a measurable metric, such as the share of successful responses or p99 latency. An SLO (objective) is the target for it: "p99 ≤ 800 ms and errors < 0.1% over a 15-minute plateau". Without an SLO, 400 ms is neither good nor bad.
2. Baseline. First measure one request and low concurrency on the same environment. Then the load grows, and changes are judged against the baseline, not against abstract "expectations".
3. A realistic scenario. A mix of requests as in production (say, 80% reads and 20% writes), not the single lightest endpoint. Different users and data: with one account everything lands in the cache and the result is optimistic. The data volume is close to production, because everything is fast on an empty database.
4. The run. Warm-up and a gradual ramp-up: cold caches, JIT and empty connection pools distort the first minutes. You measure the plateau and do not mix the first run into the results.
5. Analysis. Look at percentiles, the error rate (5xx, timeouts, 429), throughput and how latency grows with load: the point where the curve bends sharply upward is the capacity limit. Server resources (CPU, memory, the database connection pool, queues) show where the bottleneck is.
Example: a scenario with warm-up, a plateau and a threshold
The load stages describe the ramp-up, the plateau and the search for the limit. A threshold with abortOnFail stops the test if the system has already broken the SLO, so you do not burn time or take down a shared environment. Here the threshold covers the whole run, warm-up included; to judge the plateau alone, warm-up goes into a separate scenario and the threshold is set on http_req_duration{scenario:plateau}, while delayAbortEval keeps the first samples from aborting the test:
export const options = {
scenarios: {
ramp: {
executor: 'ramping-arrival-rate',
startRate: 20,
timeUnit: '1s',
preAllocatedVUs: 100,
maxVUs: 500,
stages: [
{ target: 100, duration: '2m' }, // warm-up and ramp
{ target: 100, duration: '15m' }, // measured plateau
{ target: 300, duration: '5m' }, // search for the limit
],
},
},
thresholds: {
http_req_duration: [{ threshold: 'p(99)<800', abortOnFail: true, delayAbortEval: '2m' }],
http_req_failed: ['rate<0.001'],
},
};
Data comes from a users file so every request goes from a different account. SharedArray keeps it in memory once for all virtual users:
import { SharedArray } from 'k6/data';
import http from 'k6/http';
const users = new SharedArray('users', () => JSON.parse(open('./users.json')));
export default function () {
const u = users[(__VU * 1000 + __ITER) % users.length]; // a different user each time
http.get(__ENV.BASE_URL + '/v1/accounts/' + u.accountId, {
headers: { Authorization: 'Bearer ' + u.token },
});
}
Now reading the result. Suppose at 100 requests per second p99 = 600 ms, and at 300 the latency jumped to 4 s and timeouts appeared. The limit lies between 100 and 300 requests per second. Server metrics showed the database connection pool at 100% while CPU stayed at 40%. The conclusion for the team: the bottleneck is the connection pool, not computation, so adding CPUs will not help.
Limits and alternatives
- A test on a weaker environment proves nothing about production. The environment is described in the report: which instance, how many CPUs, what data volume.
- A test against a service with mocked dependencies measures only the service itself. For the capacity of the whole path you need at least a surrogate of the real dependency with a realistic delay.
- The load generator itself can become the bottleneck. Watch its CPU and network and, if needed, run a distributed test.
- One run is not proof: estimate the spread between runs by repeating the test at least three times.
- In production, monitoring and canary checks are preferred, and load tests stay on a test environment. A test on production needs agreement.
Common mistakes
- One account and one endpoint. The cache answers instead of the system, and the numbers have no connection to real traffic.
- Running without an SLO. There is nothing to judge the result by, and the discussion comes down to taste.
- Measuring the cold first minutes. Warm-up is hidden or moved into a separate stage.
- Concluding only the fact and not the cause. "Slow" without server metrics does not say what to fix.
Check yourself
A test with one test account showed p95 = 80 ms, while in production users complain about 900 ms. What is most likely wrong with the test?
Answer
All requests went to the same data, so the cache or hot database pages served them. You need different users and data with a volume close to production, and only then will p95 be comparable.
Why is warm-up not included in the measured part of the test?
Answer
Cold caches, empty connection pools and JIT warm-up make the first minutes slower than steady operation. If they are included in the measurement, p99 is inflated and does not reflect the plateau. Warm-up stays in the scenario but is excluded from the threshold.