QA Interview Hub · Knowledge base · Quizzes · Українська

API › Performance and reliability

Kinds of load tests and percentiles

Load checks the SLO at expected traffic, stress looks for the capacity limit, spike models a sudden jump, and soak looks for leaks. The result is read in percentiles p95 and p99, not the average, because response time has a long tail. Percentiles of different runs are computed from raw measurements rather than averaged, and k6 thresholds give CI an automatic verdict.

API · Load

The average response time is 300 ms, yet users complain about freezes. What is wrong with that number?

The dashboard shows an average of 314 ms and green ticks. Meanwhile support writes that a page sometimes takes four seconds to load. Both observations are true: the average simply erases the slow minority. This lesson answers two questions: which kind of load test fits which problem, and why the result is read in percentiles.

How it works

Load tests differ by the shape of the load curve over time, not by the tool. Each shape answers its own question:

Four load shapes

Loadexpected load, constant Stressgrow to the limit and beyond Spikea sharp burst and a return Soakmoderate, for hours
Figure 1. The curve decides the question: do we hold the SLO, where is the limit, do we recover from a burst, does anything leak over a long time.

Load checks that the SLO holds at the expected traffic. Stress raises the load above normal until something breaks: that finds the capacity limit and shows how the system degrades (slows down gradually or falls in a cascade). Spike models a sudden jump, such as a newsletter or a sale: it matters not only to survive but to recover afterwards. Soak holds a moderate load for hours so that memory leaks, an exhausted connection pool, growing logs or queues show up.

Why percentiles and not the average. Response time has a long tail: most requests are fast and a minority is very slow. The average mixes both groups into one number that describes neither:

1000 requests: 950 take 120 ms, 50 take 4000 ms
average = (950 * 120 + 50 * 4000) / 1000 = 314 ms   looks fine
p95     = 120 ms   (the 950th request is still fast)
p99     = 4000 ms  (the slow tail)

p95 means 95% of requests are faster than this value, p99 the same for 99%. The tail matters more than it seems: a page is built from about ten API requests, and the chance that at least one lands in the slow 1% is already around 10%. That is why an SLO is written in percentiles: "p95 < 500 ms and p99 < 1200 ms at 200 requests per second, errors under 0.1%".

Example: a k6 scenario with thresholds

The test describes not "a number of users" but the arrival rate of requests (an open model), so a slow response does not reduce the load. Thresholds turn the SLO into an automatic verdict: if a threshold is breached, k6 exits with a non-zero code and CI goes red.

import http from 'k6/http';

export const options = {
  scenarios: {
    steady: {
      executor: 'constant-arrival-rate',
      rate: 200, // 200 new requests per second
      timeUnit: '1s',
      duration: '10m',
      preAllocatedVUs: 100,
      maxVUs: 400,
    },
  },
  thresholds: {
    http_req_duration: ['p(95)<500', 'p(99)<1200'],
    http_req_failed: ['rate<0.001'], // errors under 0.1%
  },
};

export default function () {
  http.get(__ENV.BASE_URL + '/v1/products?limit=20');
}

A closed scenario of "50 virtual users, each waiting for a response" behaves differently: when the server slows down, users send fewer requests and the system looks better than it is. This effect is called coordinated omission, and an arrival rate removes it.

Limits and alternatives

  • Percentiles of different runs or instances are not averaged: a mean of p95 values means nothing. Collect raw measurements or histograms and compute the percentile from them.
  • Few requests give an unstable p99: with 100 requests, p99 is decided by a single request. The tail needs hundreds or thousands of measurements.
  • The tool is chosen for the team: k6 (JavaScript scripts), Gatling (Java, Kotlin, Scala, and also JavaScript and TypeScript), JMeter (GUI and XML plans), Locust (Python). The shape of the scenario matters more than the brand.
  • A test on an empty database or a weaker environment measures the wrong thing. Data and configuration are brought close to production, and the threshold is compared with a baseline.

Common mistakes

  • Looking only at the average. The tail that every hundredth user sees stays invisible.
  • One test type "for everything". Load will not find a memory leak, and soak will not show behaviour during a spike.
  • Generating load from one weak laptop. The generator becomes the bottleneck instead of the service, so the numbers lie.
  • Running against production without agreement. A load test can take down shared services and trigger anti-fraud and rate limits.

Check yourself

After a release the average did not change, but p99 grew from 600 ms to 3 s. Is that a reason to worry and what can it mean?

Answer

Yes. The average still reflects the bulk of fast requests, while a slow minority could have become much slower: a new slow branch, a database lock, a cold cache or a rare query without an index. Next, look at which endpoints and parameters make up the tail.

For which test (load, stress, spike, soak) is a long history of memory metrics useful, and why?

Answer

For soak. A memory or connection leak shows as a slow linear growth that is invisible within the minutes of a load test. Soak holds a moderate load for hours, and the trend becomes obvious.

In an interview. Junior: Load checks the expected load, stress looks for the limit, spike models a sharp burst, soak looks for leaks over a long time. I judge the result by p95 and p99, not by the average, because the average hides the slow tail. Middle/Senior: I write the SLO in percentiles and set them as k6 thresholds so CI gives the verdict itself. I pick an open model (arrival rate) to avoid coordinated omission, and I compute percentiles from raw measurements instead of averaging across instances.

More articles in this chapter