How to calculate the iteration duration time?

How to calculate the iteration duration time without the setup function time?

The document wrote that:

The time it took to complete one full iteration of the default/main function.
But it doesn’t work in my case. The duration of the iteration includes the duration of the “SETUP” function.

My script

import { sleep } from "k6"

export const options = {
    scenarios: {
        checks: {
            executor: "per-vu-iterations",
            vus: 1,
            iterations: 1,
            maxDuration: "1m",
        },
    }
}

export function setup() {
    sleep(10);
}

export default function () {
    sleep(1);
}

Report:
image

k6 version: loadimpact/k6:latest

Hi @dilshod,
unfortunately, we don’t have yet a dedicated feature for supporting it, however a workaround is available. It requires setting a threshold for iteration_duration:

export let options = {
    thresholds: {
        'iteration_duration{scenario:default}': [ `max>=0` ],
   }
}

You can see a more complete script for the workaround in this PR comment.

Regarding documentation, we are already working on improving it.

1 Like