Skip to content

Commit 6380e02

Browse files
[fix] Correct gracefulRampDown explanation (#1093)
fixes #1062
1 parent 5717e38 commit 6380e02

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

src/data/markdown/translated-guides/en/02 Using k6/14 Scenarios/00 Concepts/04 Graceful stop.md

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ The `gracefulStop` is a period at the end of the test in which k6 lets iteration
77

88
If a test has a set duration or ramp down, its possible that k6 could interrupt iterations in progress.
99
These interruptions can lead to skewed metrics and unexpected test results.
10-
To deal with this, k6 scenarios have a `gracefulStop` and `gracefulRampDown` options.
10+
To deal with this, k6 scenarios have a `gracefulStop`.
11+
For the `ramping-vus` executor, a related option, `gracefulRampDown`, exists to let VUs finish as their number ramps down.
1112

1213

13-
## Description
14+
## Graceful stop
1415

15-
This option is available for all executors except `externally-controlled` and allows the
16-
user to specify a duration to wait before forcefully interrupting them. The default value
17-
of this property is `30s`.
16+
The `gracefulStop` option is available for all executors except `externally-controlled`.
17+
It specifies a duration that k6 will wait before forcefully interrupting an iteration.
18+
The default value is `30s`.
1819

19-
## Example
20+
### Graceful stop example
2021

2122
<CodeGroup labels={[ "graceful-stop.js" ]} lineNumbers={[true]}>
2223

@@ -54,8 +55,42 @@ Notice that even though the total test duration is 10s, the actual execution tim
5455
because of `gracefulStop`, giving the VUs a 3s additional time to complete iterations in progress. 23
5556
of the iterations currently in progress did not complete within this window and was therefore interrupted.
5657

57-
## Additional Information
58+
## The `gracefulRampDown`
59+
60+
In addition to `gracefulStop`, the [ramping-vus](/using-k6/scenarios/executors/ramping-vus) executor also has a `gracefulRampDown`.
61+
62+
When the target value for a stage is lower than the target for the previous stage, k6 might need to stop some VUs that were started during the previous stages.
63+
The `gracefulRampDown` option controls how long these VUs have to finish currently before k6 interrupts them.
64+
65+
To get an idea of how `gracefulRampDown` works, you can run the following script with
66+
`k6 run --verbose`.
67+
In this script, the iteration `sleep` time exceeds the `gracefulRampdown` time.
68+
So, as k6 ramps down to reach the target of the second stage, it must forcibly interrupt VUs.
69+
The `--verbose` flag will log to your console when VUs start, enter the grace period, and are forcibly interrupted.
70+
71+
```javascript
72+
import http from "k6/http";
73+
import { sleep } from "k6";
74+
75+
export const options = {
76+
discardresponsebodies: true,
77+
scenarios: {
78+
contacts: {
79+
executor: "ramping-vus",
80+
startvus: 0,
81+
stages: [
82+
{ duration: "10s", target: 10 },
83+
{ duration: "10s", target: 0 },
84+
],
85+
gracefulRampDown: "1s",
86+
},
87+
},
88+
};
89+
90+
export default function () {
91+
http.get("https://test.k6.io/contacts.php");
92+
// adding sleep beyond so that iterations are longer than rampdown
93+
sleep(5);
94+
}
95+
```
5896

59-
A similar option exists for the [ramping-vus](/using-k6/scenarios/executors/ramping-vus) executor: `gracefulRampDown`. This
60-
specifies the time k6 should wait for any iterations in progress to finish before
61-
VUs are returned to the global pool during a ramp down period defined in `stages`.

0 commit comments

Comments
 (0)