What determines the timing of VU ramp‑down between stages in k6 load tests?
0 reputation · 15 Sept 2020, 04:32 UTC
0 reputation · 15 Sept 2020, 04:32 UTC
The goal is to predict the exact moment k6 begins to reduce the number of virtual users after a stage ends, so that low‑traffic workloads can stay within the free‑tier VU‑minute quota.
The documentation defines each stage by a target VU count and a duration, but it does not state whether the ramp‑down starts instantly at the stage boundary or only after the current VU iteration finishes, nor does it specify the shape of the ramp‑down curve. This uncertainty makes it hard to verify the actual VU‑minute consumption of a test that uses a brief high‑load stage followed by a low‑load stage.
Does k6 start ramp‑down immediately at the stage boundary, or does it wait for the current VU iteration to complete? Does the ramp‑down follow a linear gradient over the stage’s duration, or is it applied as a step change? How does this behavior affect the total VU‑minute count for a low‑traffic test that uses a short high‑load stage followed by a low‑load stage?
k6 starts the VU ramp‑down immediately when the next stage begins. The target VU count for the new stage is applied linearly over the duration you specify. The only delay that can make the observed VU count lag behind the theoretical target is the time it takes a VU that is scheduled to be removed to finish its current iteration.
__VU and the time stamp at the start of each iteration.
export default function () {
console.log(`VU ${__VU} start at ${Date.now()}`);
sleep(1);
}
10 VUs for 10s, then 2 VUs for 10s.
k6 run --vus 10 --duration 10s --stages '10,10s|2,10s' script.js
vus metric over time. The graph should show a straight line from 10 to 2 during the second stage, with a slight horizontal lag if the iteration takes longer than the instant of removal.To refine the estimate of how much the VU‑minute count will be inflated, please provide the average duration of a VU iteration in your script. Knowing this will let you calculate the maximum extra VU‑minutes caused by the “finish‑iteration‑first” policy.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.