Back To Blogs

Performance Testing Basics: Load, Stress, Soak and Spike Tests (With a k6 Example)

Functional tests tell you whether a feature works. Performance tests tell you whether it keeps working when many people use it at once, for a long time, or all of a sudden. Performance problems are often found late and cost a lot, so it pays to test early.

The main test types

TypeQuestion it answersShape
Load testDoes the system meet its targets at expected traffic?Ramp to normal peak, hold
Stress testWhere does it break, and how does it fail?Keep increasing until errors or saturation
Spike testCan it survive a sudden surge (a launch, a promo email)?Jump from low to very high instantly
Soak (endurance) testDoes it degrade over hours (memory leaks, connection exhaustion)?Moderate load for a long time
Breakpoint / capacity testWhat's the maximum sustainable throughput?Step up gradually

Metrics that matter

  • Latency percentiles: p50 (median), p95 and p99. Averages hide the slow requests that real users feel. "p95 < 500 ms" means 95% of requests finish in under half a second.
  • Throughput: requests or transactions per second
  • Error rate: the percentage of failed requests (status ≥ 400, timeouts)
  • Saturation: CPU, memory, database connections, queue lengths on the servers
  • Apdex or SLOs: whatever targets your team has agreed

Always look at latency and errors and server resources together. A fast response that's an error page isn't a success.

Designing a realistic test

  1. Pick the journeys that matter: browse → search → add to cart → checkout, or sign in → start a quiz
  2. Model the mix: most users browse; fewer buy. A test with 100% checkouts isn't realistic.
  3. Use think time: real users pause between actions
  4. Use realistic data: many different users and products, not one account hammered repeatedly (that tests caching, not your system)
  5. Set pass/fail thresholds before running, e.g. p95 < 800 ms and errors < 1%
  6. Test in a production-like environment and never against production without agreement. Load tests can take systems down.

A first load test with k6

k6 is an open-source load testing tool scripted in JavaScript.

// load-test.js
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  stages: [
    { duration: '2m', target: 50 },  // ramp up to 50 virtual users
    { duration: '5m', target: 50 },  // hold
    { duration: '1m', target: 0 },   // ramp down
  ],
  thresholds: {
    http_req_duration: ['p(95)<800'], // 95% of requests under 800 ms
    http_req_failed: ['rate<0.01'],    // less than 1% errors
  },
};

const BASE = __ENV.BASE_URL;

export default function () {
  const list = http.get(`${BASE}/api/products`);
  check(list, { 'products 200': (r) => r.status === 200 });
  sleep(Math.random() * 3 + 1); // think time: 1–4 s

  const detail = http.get(`${BASE}/api/products/mug`);
  check(detail, { 'detail 200': (r) => r.status === 200 });
  sleep(Math.random() * 3 + 1);
}

Run it against a test environment:

k6 run -e BASE_URL=https://staging.example.com load-test.js

k6 prints percentiles, throughput and threshold results, and exits non-zero when a threshold fails, so it can gate a CI pipeline.

Reading the results

  • Latency rises steadily with load → a capacity limit; look at CPU and database
  • Errors start at a specific load → a hard limit: connection pools, rate limits, memory
  • Latency creeps up over a soak test → a leak or growing table, queue or cache
  • One endpoint dominates → an unindexed query, N+1 queries or a missing cache

Report like a tester: what load, which journey, what broke, the evidence (graphs, logs) and the impact.

Performance from the user's side

Server performance is half the story. Front-end performance (how fast pages feel) is measured with Core Web Vitals; see Core Web Vitals for testers.

Keep learning

Performance testing builds on fundamentals: knowing which user journeys matter and which risks are worth testing. Sharpen those with QAUnlocked quizzes and battles, then apply them to your own system's busiest paths.

performance testingload testingk6stress testing

Comments

0 Comments

Be the first to comment.