k6 Scenarios for Advanced Load Models

Beyond simple VU and duration options, k6 scenarios let you model sophisticated load patterns such as ramping arrival rates, constant request rates and hybrid models. This makes it easier to align tests with real traffic profiles and specific performance questions.

Defining Advanced Load Models with Scenarios

The scenarios option allows you to define multiple named scenarios, each with its own executor type, VUs, duration and other settings. Common executors include ramping-vus, constant-arrival-rate and ramping-arrival-rate, which control how users or requests ramp up and down.

export const options = {
  scenarios: {
    ramping_users: {
      executor: 'ramping-vus',
      startVUs: 0,
      stages: [
        { duration: '2m', target: 50 },
        { duration: '5m', target: 200 },
        { duration: '3m', target: 0 },
      ],
      exec: 'checkoutFlow',
    },
    constant_rate: {
      executor: 'constant-arrival-rate',
      rate: 100,
      timeUnit: '1s',
      duration: '10m',
      preAllocatedVUs: 50,
      maxVUs: 200,
      exec: 'searchFlow',
    },
  },
};

export function checkoutFlow() {
  // checkout logic
}

export function searchFlow() {
  // search logic
}
Note: Arrival-rate executors focus on requests per time unit rather than virtual users, which is useful when you care about throughput more than concurrent sessions.
Tip: Choose executors based on the question you are asking: user concurrency, request rate, or a combination of both.
Warning: Mixing many complex scenarios in one script without clear goals can make results hard to interpret; keep each scenario tied to a specific hypothesis.

With scenarios, you can express nuanced performance experiments directly in code, matching patterns like campaign spikes or gradual traffic growth.

Common Mistakes

Mistake 1 โ€” Using only basic vus/duration for all tests

This oversimplifies load.

โŒ Wrong: Treating every situation as constant load.

โœ… Correct: Use scenarios and executors that reflect real traffic dynamics.

Mistake 2 โ€” Under-provisioning maxVUs in arrival-rate scenarios

This caps throughput.

โŒ Wrong: Setting maxVUs too low so k6 cannot reach the desired rate.

โœ… Correct: Size preAllocatedVUs and maxVUs to sustain target rates without hitting client limits.

🧠 Test Yourself

When is a constant-arrival-rate executor more appropriate than simple VUs and duration?