Module 2. Advanced testing · Lesson 13 of 41 · 13 min

Performance testing: load, percentiles, bottlenecks

Load, stress, spike and soak; why you look at p95 instead of the average; how to plan your first test.

Four questions about performance

  1. Can the system handle the expected load?
  2. Where is its limit, and what happens beyond it?
  3. How does it survive a sudden spike?
  4. Does it degrade over hours of operation?

Each question has its own load profile.

Load profilesLoadusers ↑time →Stressusers ↑time →Spikeusers ↑time →Soakusers ↑time →
Load profiles. Load — the expected traffic; stress — beyond the limit, looking for the breaking point; spike — a sudden burst; soak — moderate load for hours (memory leaks, degradation).

The average lies

If 95 requests take 100 ms and 5 take 3 seconds, the average is ≈ 245 ms and looks acceptable. But one user in twenty waits three seconds. That's why requirements are written in percentiles:

  • p50 (median) — the typical experience;
  • p95 — what an "unlucky" user sees;
  • p99 — the tail, where timeouts and complaints live.
Why the average lies: response time distribution0–100: 1801800–100100–200: 340340100–200200–300: 210210200–300300–400: 110110300–400400–600: 110110400–600600–1200: 4040600–12001200+: 10101200+response time, ms · number of requestsp50 ≈ 190 msp95 ≈ 600 msp99 ≈ 1.2 s
Why the average lies: response time distribution. An example distribution of 1,000 requests. The average (≈257 ms) looks fine, but 5% of users wait more than 600 ms and 1% more than 1.2 s. Performance requirements use p95/p99, not the average.
Percentile Value in the example Meaning
p50 ≈ 190 ms half of the requests are faster
p95 ≈ 600 ms 5% of the requests are slower
p99 ≈ 1.2 s 1% of the requests are slower

How to plan your first test

  1. Scenario — real user actions (search → product page → cart → checkout), not one endpoint.
  2. Profile — how many users, how fast the load ramps up, for how long.
  3. Data — realistic volumes: search on an empty database is always fast.
  4. Criteria — for example, p95 < 800 ms and errors < 1% with 500 concurrent users.
  5. Monitoring — CPU, memory, the database connection pool, queues. Without it you see the symptom, not the cause.

Tools

k6 and JMeter are the most popular for HTTP; Gatling and Locust are alternatives. A simple k6 scenario:

import http from "k6/http";
import { check } from "k6";
export const options = { vus: 50, duration: "5m", thresholds: { http_req_duration: ["p(95)<800"] } };
export default function () {
  const res = http.get("https://staging.example.com/api/products?q=phone");
  check(res, { "status 200": (r) => r.status === 200 });
}

Typical bottlenecks

N+1 database queries, missing indexes, synchronous calls to external services, large responses without pagination, memory leaks (visible only in a soak test).

Performance is part of the non-functional testing covered in the levels and types lesson.

Key takeaways

  • Load, stress, spike and soak tests answer different performance questions.
  • Requirements use p95/p99 — the average hides the tail of slow requests.
  • Without server monitoring a test shows the symptom, not the cause.

Check yourself

  1. 1. Which test looks for memory leaks?

  2. 2. Why are requirements set at p95 rather than the average?

  3. 3. Search is fast on staging but slow in production. The most likely cause?