Scenarios
Scenarios provide fine-grained control over how k6 executes your test. They allow you to model complex user behavior patterns, run different workloads in parallel, and precisely control VU execution.Why Use Scenarios?
Scenarios are more powerful than simplevus, duration, or stages options:
- Multiple workflows: Run different test functions simultaneously
- Different load patterns: Combine constant load, ramping, and spike patterns
- Precise VU control: Control exactly how VUs execute iterations
- Per-scenario configuration: Set different options for each scenario
- Advanced metrics: Get per-scenario metrics and tags
Basic Scenario Structure
Executors
Executors define how VUs are scheduled and iterations are executed. k6 provides several executor types:Constant VUs
Maintains a constant number of VUs for a duration.Ramping VUs
Gradually ramps VUs up and down.Constant Arrival Rate
Starts iterations at a constant rate, adding VUs as needed.Constant arrival rate focuses on iteration starts per time unit, not concurrent VUs. k6 will add VUs as needed to maintain the rate.
Ramping Arrival Rate
Gradually increases or decreases the iteration start rate.Shared Iterations
Shares a fixed number of iterations among VUs.Per-VU Iterations
Each VU executes a specific number of iterations.Externally Controlled
Control execution externally via k6’s REST API.Multiple Scenarios
Run different test functions with different load patterns:Scenario Configuration Options
Common Options
All scenarios support these options:Staggered Start Times
Start scenarios at different times:Scenario Tags and Metrics
Each scenario automatically gets tagged:Graceful Stop
Control how iterations finish at the end:Scenario Examples
- Spike Test
- Stress Test
- Soak Test
- Mixed Workload
Executor Comparison
Best Practices
- Use arrival rate for throughput testing - When you care about requests/second, not VU count
- Set appropriate maxVUs - For arrival rate executors, allocate enough VUs to maintain the rate
- Add graceful stop time - Give long-running iterations time to complete
- Use scenario tags - Tag scenarios for easier metric filtering
- Stagger scenario starts - Avoid overwhelming the system at test start
- Name scenarios descriptively - Use clear names like
api_load,browser_flow, etc.
Scenario Metrics
Filter metrics by scenario:Next Steps
- Learn about Tags and Groups for organizing test metrics
- Review Test Options for global configuration
- Understand Test Structure fundamentals