__VU and __ITER variables for accessing VU and iteration information.
__VU
The__VU variable contains the current VU’s unique ID.
number
Current VU ID (1-based, unique within the test)
Usage
__ITER
The__ITER variable contains the current iteration number for the VU.
number
Current iteration number (0-based)
Usage
Environment Variables
__ENV
Access environment variables passed to k6.Examples
Per-VU Data Assignment
Iteration-based Pacing
Conditional Execution
Unique Session IDs
Comparison with exec
The global variables are simpler but less feature-rich than thek6/execution module:
When to use global variables:
- Simple VU identification
- Iteration counting
- Quick prototyping
When to use k6/execution:
- Need scenario information
- Want to control test execution
- Need to set tags/metadata
- Require detailed execution state
The global variables
__VU and __ITER are available in both the init and VU contexts, but they are only meaningful in the VU context.