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
}
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.