k6 community forum

How .sleep impacts overall duration of the test

For example, I have 5-seconds sleep for a group.

.sleep(5.1)

Shouldn’t the function that contains this sleep be executed longer than without this sleep? I run the test in the cloud and neither with nor without the “sleep” I have the same duration.

Or it’s being included in the overall duration, just the number of requests will become less with sleeps encluded?

@Alexander Sleep doesn’t impact the test duration. It will impact how quickly the VUs can complete iterations of the default function and thus how many requests are made.

Consider the example below. If I ran it for 60 seconds with 1 VU, I would expect roughly 60 total requests / iterations of the script. If I changed the sleep to 60 seconds, I would expect 1 iteration / request. Sleep is an idle time for VUs. It’s mostly used for script pacing, emulating user behavior, and just load gen stability. VUs will naturally execute as quickly as possible so if you get too aggressive, you can eat up all the resources on the load gen and skew results.

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

export default function() {
  let res = http.get("https://loadimpact.com");
  sleep(1);
};
1 Like

Understood. Thank you very much for the explanation.