shared-iterations executor executes a specific total number of iterations that are shared across all configured VUs. This executor is ideal when you need to ensure a specific total number of test iterations complete, regardless of how long each iteration takes.
How It Works
With shared iterations:- A pool of VUs is created (specified by
vus) - VUs compete to execute iterations from the shared total
- The first VU to finish an iteration immediately grabs the next one
- Execution continues until all iterations complete or
maxDurationis reached - Faster VUs will execute more iterations than slower ones
Configuration
Must be
shared-iterationsNumber of VUs to run concurrently. Must be greater than 0.
Total number of script iterations to execute across all VUs. Must be greater than or equal to
vus.Maximum duration for the executor. If all iterations don’t complete within this time, the executor stops and remaining iterations are dropped.
Example
Basic Configuration
Data-Driven Testing
When to Use
Use the shared iterations executor when:- You need to process a specific amount of test data exactly once
- You want to ensure a fixed total number of operations complete
- You need to iterate through a dataset with each iteration processing one item
- The total work is more important than the execution time
- You want faster VUs to do more work
Behavior Details
VU Distribution
Iterations are not evenly distributed. VUs that complete iterations faster will execute more iterations:Maximum Duration
If iterations don’t complete withinmaxDuration, execution stops and the remaining iterations are recorded as dropped:
dropped_iterations metric.
Minimum Iterations
The number of iterations must be at least equal to the number of VUs. This ensures each VU can execute at least one iteration:Metrics
The executor emits these specific metrics:iterations- Total completed iterationsiteration_duration- Time to complete each iterationdropped_iterations- Iterations that didn’t complete withinmaxDurationvus- Number of active VUsvus_max- Maximum number of VUs
Common Patterns
Processing a Queue
Smoke Test with Exact Count
Comparison with Per VU Iterations
| Feature | Shared Iterations | Per VU Iterations |
|---|---|---|
| Total iterations | Fixed | vus × iterations |
| Distribution | Dynamic (faster VUs do more) | Even (each VU does same amount) |
| Predictability | Less predictable per-VU | More predictable per-VU |
| Use case | Process fixed dataset | Consistent per-user load |
Best Practices
- Set appropriate maxDuration: Ensure
maxDurationis long enough for all iterations to complete - Monitor dropped iterations: Check the
dropped_iterationsmetric to ensure work completes - Use SharedArray for data: When processing datasets, use
SharedArrayto avoid memory duplication - Consider execution segment: For distributed testing, iterations are split across k6 instances
See Also
- Per VU Iterations - Each VU runs a fixed number of iterations
- Constant VUs - Time-based execution with fixed VUs