k6

Finding number of iterations for a given duration

is there is any way to find number of executed iterations for given duration?

i would like to to set certain amount of iterations per minute…
ex: - 10 iterations: at the 1st min

  • 30 iterations at the 2rd min
  • 20 iterations at the 3th min
    we have tried below and its taking duration only and we are not able to limit iterations within a specified duration
    export let options = {
    stages: [
    { duration: “60s”, iterations: 10},
    { duration: “60s”, iterations: 30 }
    ]
    };

Hi @ravi_k6, this will be possible with the new schedulers and the arrival rate base execution.

You are welcome to test the PR, but it is currently under review(by me) and as it is very big and there are still things to be done I would say that at best at least 2 weeks will past before we merge it in master.

We do intend on releasing a version with (primarily) just it, as it is a huge change and our current goal is to do this by the end of June.

@ravi_k6, unfortunately you can’t do this with the current k6 version - stages does not support iterations. As @mstoykov has said, once https://github.com/loadimpact/k6/pull/1007 is merged and released though, you’d be able to run a k6 script like this:

import { check, sleep } from "k6";

export let options = {
    execution: {
        first_stage: {
            type: "shared-iterations",
            vus: 1, // or however many you need
            iterations: 10,
            maxDuration: "60s",
            gracefulStop: "0s",
        },
        second_stage: {
            startTime: "60s",
            type: "shared-iterations",
            vus: 1, // or however many you need
            iterations: 20,
            maxDuration: "60s",
            gracefulStop: "0s",
        },
        third_stage: {
            startTime: "120s",
            type: "shared-iterations",
            vus: 1, // or however many you need
            iterations: 30,
            maxDuration: "60s",
            gracefulStop: "0s",
        },
        // ...
    },
};

export default function () {
    // Do some actual work...
    sleep(Math.random() * 5);
}

Hi!
I have a question related to iterations.
There is mentioned in documentation that " Note: The number of iterations is split between all VUs."

But when I execute test with the following options:

vus: 3,
iterations: 6

The output is like this:

VU: 1, Iter: 0
VU: 2, Iter: 0
VU: 1, Iter: 1
VU: 2, Iter: 1
VU: 1, Iter: 2
VU: 3, Iter: 0

One extra iteration for 1st user, and one iteration less than expected for the 3rd

And same results for different input options
Why?

Thx :slight_smile:

The current way k6 works is that the number of iterations you specify is shared between VUs - if one VU finishes an iteration faster than the others, it will “steal” work from the common pile and start executing the next iteration, even if other VUs are still running the previous ones.

That is something else that will be improved by https://github.com/loadimpact/k6/pull/1007 - there you’d be able to specify if the iterations are going to be per VU or shared among all VUs.

1 Like