No results for

Powered byAlgolia
⚠️ This is archived documentation for v0.32. Go to the latest version

sleep( t )

suggest edits

Suspend VU execution for the specified duration.

sleep is the primary means of introducing delays in your script. These delays aim to represent the time it would take a real user to parse a page before proceeding to the next page, commonly referred to as "think time". Without sleep statements, a script will run as quickly as the system it runs on allows it, as well as by how fast the server(s) it communicates with responds (because k6 executes HTTP requests synchronously).

Unless you are stress testing and want each VU to execute as many requests per second as possible, you should aim to include sleep statements throughout the script in order to relate your VUs activity to that of real users.

Ideally, you would also feed in a randomized pause duration as that further encourages natural concurrency to develop.

ParameterTypeDescription
tnumberDuration, in seconds.

Examples

Fetching two different pages with a 0-30 second random sleep in between:

import { sleep } from 'k6';
import http from 'k6/http';
export default function () {
http.get('https://k6.io');
sleep(Math.random() * 30);
http.get('https://k6.io/features');
}

Using the k6-utils library to specify a range between a minimum and maximum:

import { sleep } from 'k6';
import http from 'k6/http';
import { randomIntBetween } from "https://jslib.k6.io/k6-utils/1.1.0/index.js";
export default function () {
http.get('https://k6.io');
sleep(randomIntBetween(20, 30));
http.get('https://k6.io/features');
}