No results for

Powered byAlgolia

Graceful stop

suggest edits

Prior to v0.27.0, k6 would interrupt any iterations in progress when the test duration was reached or when scaling down VUs with the stages option. In some cases this would lead to skewed metrics and unexpected test results. Starting with v0.27.0, this behavior can be controlled through the gracefulStop and gracefulRampDown options.

Description

This option is available for all executors except externally-controlled and allows the user to specify a duration to wait before forcefully interrupting them. The default value of this property is 30s.

Example

graceful-stop.js
1import http from 'k6/http';
3export let options = {
4 discardResponseBodies: true,
5 scenarios: {
6 contacts: {
7 executor: 'constant-vus',
8 vus: 100,
9 duration: '10s',
10 gracefulStop: '3s',
11 },
12 },
13};
15export default function () {
16 let delay = Math.floor(Math.random() * 5) + 1;
17 http.get(`https://httpbin.test.k6.io/delay/${delay}`);
18}

Running this script would result in something like:

running (13.0s), 000/100 VUs, 349 complete and 23 interrupted iterations
contacts ✓ [======================================] 100 VUs 10s

Notice that even though the total test duration is 10s, the actual execution time was 13s because of gracefulStop, giving the VUs a 3s additional time to complete iterations in progress. 23 of the iterations currently in progress did not complete within this window and was therefore interrupted.

Additional Information

A similar option exists for the ramping-vus executor: gracefulRampDown. This specifies the time k6 should wait for any iterations in progress to finish before VUs are returned to the global pool during a ramp down period defined in stages.