Skip to content

Performance Testing

A performance test answers a specific question with a number: “how many requests per second can this service sustain at p95 under 300 ms before errors start?” Without the question, you get a graph nobody can act on.

“Load testing checks behaviour at expected traffic; stress testing finds the breaking point by raising load until the system degrades; soak testing holds a moderate load for hours to expose leaks. You drive it with a tool like k6 or JMeter, model a realistic mix of endpoints with realistic think time, and watch four numbers: latency percentiles, throughput, error rate and resource saturation. Percentiles matter more than averages because averages hide the tail — p95 and p99 are what users experience during a spike. The output is a bottleneck and a capacity number, not a pass/fail badge.”

Type Load profile Question it answers
Smoke 1–5 users, short Does the script work and is the environment sane?
Load Expected peak, steady Do we meet the SLO at normal traffic?
Stress Ramp past peak until failure Where does it break, and how does it fail?
Soak 60–70% of peak for hours Do memory, connections or disk degrade?
Spike Sudden jump, then back Can we absorb a burst without cascading?

Always run a smoke test first. Most “the system is slow” results are a broken script or a cold database.

Two numbers define a test more than any tool setting:

  • Virtual users (VUs) — concurrent simulated users. If each waits 2 s between requests, 50 VUs produce roughly 25 requests per second, not 50.
  • Think time / pacing — the delay between actions. Removing it turns a user simulation into a benchmark no real traffic resembles.

Little’s Law connects them: concurrency = throughput × latency. If you need 200 RPS at 100 ms, you need about 20 requests in flight. It is the quickest sanity check that a result is plausible.

load.js
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
scenarios: {
browse: {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{ duration: '2m', target: 50 }, // ramp up
{ duration: '5m', target: 50 }, // steady state
{ duration: '1m', target: 0 }, // ramp down
],
},
},
thresholds: {
http_req_duration: ['p(95)<300', 'p(99)<800'],
http_req_failed: ['rate<0.01'],
},
};
export default function () {
const list = http.get(`${__ENV.BASE_URL}/products`);
check(list, { 'list 200': (r) => r.status === 200 });
const detail = http.get(`${__ENV.BASE_URL}/products/${list.json('data.0.id')}`);
check(detail, { 'detail 200': (r) => r.status === 200 });
sleep(1 + Math.random()); // think time
}

thresholds turn the test into a CI gate. k6 reports http_req_duration with avg, min, max, p(90), p(95) and p(99) by default. JMeter is the older GUI-driven alternative: thread groups for VUs, samplers for requests, and a .jmx file in version control — heavier, but common in enterprises and supports many protocols. Gatling (Scala DSL) and Locust (Python) are the other tools you will meet.

Metric Meaning Watch for
Throughput Requests per second actually served Plateaus while latency rises = saturation
p50 Median latency The typical user
p95 / p99 Tail latency The users who complain; drives SLOs
Error rate Non-2xx plus timeouts Rising before latency? Look at a dependency
Saturation CPU, memory, connections, queue depth The actual constraint

Why not the average: with 99 requests at 10 ms and one at 5 s, the mean is 60 ms and the p99 is 5 s. Real traffic has heavy tails, and the tail is where timeouts and retries amplify load.

typical k6 summary lines
http_req_duration..............: avg=84ms min=12ms med=61ms max=2.1s p(90)=140ms p(95)=210ms p(99)=780ms
http_req_failed................: 0.42% ✓ 210 out of 50,000
http_reqs......................: 50,000 138.9/s
vus_max........................: 50

The median is fine, the tail is not: 1% of requests take 780 ms, which suggests a queue or a GC pause rather than uniform slowness. The error rate is under threshold, so the test passes — and the p99 is still the thing to investigate. A useful report has four parts:

  1. The shape of the curve. Plot latency against throughput. Below the knee it is flat; above it, latency rises steeply as queues form. That knee is your capacity.
  2. The bottleneck. The saturation metric that hits 100% first is the constraint.
  3. The failure mode. Graceful (429s, load shedding) or catastrophic (timeouts, cascading retries, OOM)? Failure mode is an architecture property, not a performance one.
  4. The comparison. Against the previous build, the SLO or the traffic forecast. A number without a baseline is trivia.
  • Never point load tests at production without an explicit agreement, a rate limit and a kill switch. You will page someone.
  • Isolate the environment. Shared staging gives noise, not measurements.
  • Seed realistic data volumes. A 100-row table hides every index problem.
  • Warm up caches and JIT before measuring the steady state.
  • Change one variable at a time, and record the commit, config and dataset with the result.
  1. Why can p99 be terrible while p50 is excellent, and what causes that?
  2. What do a load test and a stress test teach you that the other does not?
  3. How would you test a system whose traffic is spiky rather than steady?
  4. Which metric tells you the system is saturated rather than just slow?
  • Reporting averages. They hide the tail that users feel.
  • No think time. You benchmark a machine, not a user journey.
  • Testing with an empty database. Every query is fast at 100 rows.
  • Ignoring the client and network. Server timings omit DNS, TLS and payload size.
  • Treating one run as truth. Variance is large; repeat and compare distributions.