No results for

Powered byAlgolia

Execution context variables

suggest edits

✨ Execution API (since v0.34.0)

The k6/execution module exports an idiomatic alternative for getting the same values as __VU and __ITER and some other information about the execution state.

The "Running k6" tutorial describes how k6 runs a test script for a specified number of Virtual Users (VUs) and duration of time or a fixed number of iterations for each VU.

When the duration option is specified, k6 will continuously run the test script for each VU until the duration amount of time has elapsed.

1$ k6 run --vus 10 --duration 30s script.js

Alternatively, you could set the iterations option to specify the number of complete loops of the test script k6 will execute for each VU.

1$ k6 run --vus 10 --iterations 100 script.js

__VU and __ITER

__VU and __ITER are both global variables with execution context information that k6 makes available to the test script.


A numeric counter with the current iteration number for a specific VU. Zero-based.


Current VU number in use. The value is assigned incrementally for each new VU instance, starting from one. The variable will be 0 while executing the setup and teardown functions.

⚠️ Running in the k6 Cloud

When you run your tests in the k6 Cloud, the __VU value you get will be per server/load generator. You can read the details in the cloud docs.

In k6 Cloud you will also have additional environment variables that will tell you on which server, load zone and distribution of the test you are currently executing.

k6 Test Coordinator

k6 Virtual Users are concurrent, they will continuously execute through their script until the test is over or they hit their iteration limit (if you set one as described above). When you ramp up more Virtual Users, k6 will start new ones at that time. When you ramp down, k6 will stop them after the completion of the iteration.


1import http from 'k6/http';
2import { sleep } from 'k6';
4export default function () {
5 http.get('');
6 console.log(`VU: ${__VU} - ITER: ${__ITER}`);
7 sleep(1);

Different test behaviors and parameterizations can be accomplished by making use of the execution context variables. A typical use case would be a load test simulating different users performing a login flow.

1import http from 'k6/http';
2import { sleep } from 'k6';
4export default function () {
5 const email = `user+${__VU}`;
6 const payload = JSON.stringify({ email: email, password: 'test' });
7 const params = { headers: { 'Content-Type': 'application/json' } };
8'', payload, params);
9 console.log(email);
10 // .. continue the user flow
12 sleep(1);