A modern load testing tool, using Go and JavaScript

"like unit testing, for performance"

k6 is a modern load testing tool, building on Load Impact's years of experience. It provides a clean, approachable JavaScript scripting API, distributed and cloud execution, and orchestration via a REST API.

Get Started    Guides

Execution context variables

The "Running k6" tutorial describes how k6 runs a test script for a specified number of Virtual Users (VUs) and duration of time or, alternatively, 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.

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.

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

__VU and __ITER

There are a couple of global variables with execution context information that k6 makes available to the load script, namely __VU and __ITER.

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

Current VU number. The value is assigned incrementally for each new VU instance. One-based. However, VU number is 0 while executing the setup and teardown functions.

Additional context information available in Load Impact Cloud

If you are running a test in Load Impact Cloud you will have additional environment variables that will tell you on which server, load zone and distribution of the test you are currently executing. You can read more about them here

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.


import http from "k6/http";
import { sleep } from "k6";

export default function() {
  console.log(`VU: ${__VU}  -  ITER: ${__ITER}`);

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.

import http from "k6/http";
import { sleep } from "k6";

export default function() {
  const email = `user+${__VU}@mail.com`;
  const payload = JSON.stringify({ email: email, password: "test" });
  const params =  { headers: { "Content-Type": "application/json" } }
  http.post("http://test.loadimpact.com/login", payload, params);
  // .. continue the user flow


Execution context variables

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.