Skip to main content

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 simple vus, 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.
Use case: Steady-state load testing

Ramping VUs

Gradually ramps VUs up and down.
Use case: Gradually increasing load, soak testing

Constant Arrival Rate

Starts iterations at a constant rate, adding VUs as needed.
Use case: Testing system under constant request rate, measuring latency under load
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.
Use case: Gradually increasing throughput testing

Shared Iterations

Shares a fixed number of iterations among VUs.
Use case: Completing a specific number of test iterations as quickly as possible

Per-VU Iterations

Each VU executes a specific number of iterations.
Use case: Testing with a precise total number of iterations (vus × iterations)

Externally Controlled

Control execution externally via k6’s REST API.
Use case: Dynamic control of VUs during test execution

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:
If iterations don’t complete within the gracefulStop period, they are forcefully terminated.

Scenario Examples

Executor Comparison

Best Practices

  1. Use arrival rate for throughput testing - When you care about requests/second, not VU count
  2. Set appropriate maxVUs - For arrival rate executors, allocate enough VUs to maintain the rate
  3. Add graceful stop time - Give long-running iterations time to complete
  4. Use scenario tags - Tag scenarios for easier metric filtering
  5. Stagger scenario starts - Avoid overwhelming the system at test start
  6. Name scenarios descriptively - Use clear names like api_load, browser_flow, etc.

Scenario Metrics

Filter metrics by scenario:

Next Steps