Menu
Open source
sleep( t )
Suspend VU execution for the specified duration.
Parameter | Type | Description |
---|---|---|
t | number | Duration, in seconds. |
Examples
Fetching two different pages with a 0-30 second random sleep in between:
JavaScript
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:
JavaScript
import { sleep } from 'k6';
import http from 'k6/http';
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
export default function () {
http.get('https://k6.io');
sleep(randomIntBetween(20, 30));
http.get('https://k6.io/features');
}
Was this page helpful?
Related documentation
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video
Performance testing and observability in Grafana Cloud
In this webinar, learn how Grafana Cloud k6 offers you the best developer experience for performance testing.
User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.