Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 36 ยท Patterns and Analysis

Test Design: Workload Models, Think Time and Little's Law

Design realistic load tests: closed versus open workload models, think time and pacing, Little's Law for sizing VUs, test types (smoke, load, stress, spike, soak) and how to model a traffic mix.

The syntax of k6 takes an afternoon to learn. The hard part of load testing is deciding what to simulate. A technically perfect script that models traffic nobody will ever send gives you confident, useless numbers. This lesson is about the model behind the script: who the users are, how often they arrive, how long they pause, and how many of them you need.

Honesty note. k6 cannot run on this site. The k6 options are read-only. Runnable blocks are Node simulations (deterministic arithmetic and a small queue model) that demonstrate the concepts, not measurements of a real system.

Start from questions, not VUs

Before writing code, answer:

  1. What is the goal? Verify an SLO (p(95) under 400 ms at expected peak), find the breaking point, check for leaks over hours, or validate a new release?
  2. What does real traffic look like? Use production analytics or logs: requests per second at peak, the share of each journey (browse 70 %, search 20 %, checkout 5 %), session length.
  3. What is the acceptance criterion? Write it as thresholds before you run anything. Deciding after seeing the graphs invites wishful reading.

Closed versus open models

This is the most important distinction in workload design.

Closed model. A fixed number of users loop: send a request, wait for the response, think, repeat. If the server slows down, users wait longer and the number of requests per second drops. In k6 these are the VU-based executors: constant-vus, ramping-vus, per-vu-iterations, shared-iterations.

Open model. Users arrive at a fixed rate no matter how the system is doing, like customers entering a shop. If the server slows down, requests pile up. In k6 these are the arrival-rate executors: constant-arrival-rate and ramping-arrival-rate.

Property Closed (VUs) Open (arrival rate)
What you fix Concurrent users Arrivals per second
Under slowdown Throughput falls (load self-throttles) Queue grows, latency explodes
Models Internal tools, batch workers, logged-in sessions Public websites and APIs with independent visitors
Risk Hides overload (the test "backs off") Needs enough maxVUs, can overwhelm quickly

A public shop does not slow its visitors down: people keep arriving. Testing it with a closed model can make a saturated server look healthy, because the virtual users politely wait. This effect is sometimes called coordinated omission: the slow periods are under-sampled because the load generator waits along with the server.

JavaScript
export const options = {
  scenarios: {
    visitors: {
      executor: 'ramping-arrival-rate',
      startRate: 5,
      timeUnit: '1s',
      preAllocatedVUs: 50,
      maxVUs: 500,
      stages: [
        { target: 50, duration: '2m' },   // ramp to 50 new visitors per second
        { target: 50, duration: '10m' },  // hold
        { target: 0, duration: '1m' },
      ],
    },
  },
};
Node.js Stand-in: a closed and an open model against a server that can do 10 req/s

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Think time and pacing

Real users read, type and decide. Without sleep() a VU fires requests back to back and a "user" becomes a hammer: 100 VUs without think time can generate more load than 5,000 real visitors. Two tools:

  • Think time: sleep(randomIntBetween(1, 5)) between steps (import randomIntBetween from https://jslib.k6.io/k6-utils/1.4.0/index.js). Randomizing avoids all VUs acting in lockstep.
  • Pacing: keep each iteration to a target length, regardless of how long the requests took. Arrival-rate executors do this for you.

When you remove think time you change the question from "can the system handle 500 users?" to "how fast can it respond to maximum pressure?". Both are valid, but be clear which one you are asking.

Sizing: Little's Law

Little's Law relates three numbers in any stable system:

TEXT
concurrent users (VUs) = arrival rate x time each user spends in the system

If 40 visitors arrive per second and each iteration (requests plus think time) takes 12 seconds, you need about 40 x 12 = 480 VUs. This is how you pick preAllocatedVUs and maxVUs for an arrival-rate scenario, and how you convert "requests per second" from analytics into a VU count for a closed model.

Node.js Stand-in: sizing VUs with Little's Law

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The traffic mix

One script that runs every endpoint equally is almost never realistic. Use separate scenarios (or weighted branches) that reflect the real mix:

JavaScript
export const options = {
  scenarios: {
    browse:   { executor: 'constant-arrival-rate', exec: 'browse',   rate: 70, timeUnit: '1s', duration: '10m', preAllocatedVUs: 100 },
    search:   { executor: 'constant-arrival-rate', exec: 'search',   rate: 20, timeUnit: '1s', duration: '10m', preAllocatedVUs: 50 },
    checkout: { executor: 'constant-arrival-rate', exec: 'checkout', rate: 5,  timeUnit: '1s', duration: '10m', preAllocatedVUs: 50 },
  },
};

Rates of 70, 20 and 5 per second give the 70 : 20 : 5 mix. Each function (browse, search, checkout) is exported from the same file and tagged by scenario, so thresholds can target each journey separately.

Shapes of load: the common test types

Type Shape Question it answers
Smoke Tiny, short Does the script and the system work at all?
Load Expected peak, held 10-60 min Does it meet the SLO at normal and peak traffic?
Stress Beyond peak, stepwise How does it behave and recover under too much?
Spike Sudden jump and drop Can it absorb a flash crowd?
Soak Normal load for hours Memory leaks, connection exhaustion, log growth
Breakpoint Rising until failure Where is the limit?
flowchart LR
    A["Smoke"] --> B["Load"]
    B --> C["Stress"]
    B --> D["Spike"]
    B --> E["Soak"]
    C --> F["Breakpoint"]

Start small; each type adds a question once the previous one passes.

Common design mistakes

  1. No think time, then claiming the result represents users.
  2. Using a closed model for public traffic and missing saturation.
  3. Ramping up instantly: always ramp, then hold, then ramp down.
  4. A test environment much smaller than production without scaling the target accordingly.
  5. Warm caches in the test, cold caches in real life (or the reverse). Say which one you tested.
  6. Judging after the fact instead of writing thresholds first.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which k6 executor family models an open workload?

    Arrival-rate executors start iterations at a fixed rate regardless of how fast the system responds, which is the open model.
  2. 2. Why can a closed model make an overloaded server look healthy?

    Closed VUs only send the next request after the previous one finishes, so slowdowns reduce the load itself.
  3. 3. 40 visitors arrive per second and each iteration takes 12 seconds. How many VUs do you need (Little's Law)?

    VUs = arrival rate x time in system = 40 x 12 = 480.
  4. 4. What is a soak test for?

    Soak tests run realistic load for hours to reveal resource leaks and slow degradation.

Summary

  • Start from the goal, the real traffic mix and thresholds written in advance.
  • Use arrival-rate executors for independent visitors and VU executors for fixed populations.
  • Add think time; size VUs with Little's Law.
  • Pick the test type that matches your question: smoke, load, stress, spike, soak or breakpoint.

Next: Data, Parameterization and Shared Files