Different minimum iteration duration per scenario

Hi,

i am trying to use a different minimum iteration duration option per scenario.

I tried using the code option and the environment variables (per code option), but both values will not be used:

export const options = {
  minIterationDuration: '10s', // this works but is then set for all szenarios
  scenarios: {
    example_scenario: {
      executor: 'constant-vus',
      minIterationDuration: '15s', // this does not work
      env: { K6_MIN_ITERATION_DURATION: '15s' },  // this does not work
      vus: 10,
      iterations: 200,
      // ...
    },
    another_scenario: {
      executor: 'constant-vus',
      minIterationDuration: '20s', // this does not work
      env: { K6_MIN_ITERATION_DURATION: '20s' },  // this does not work
      vus: 10,
      iterations: 100,
      // ...
    },
  },
};

Is there a way tu use a different minimum iteration duration option per scenario?

Thanks

Hi @klosef

Welcome to the community forum :wave:

On a side note, in the example you share you have a 'constant-vus' executor, which does not allow the iterations option, or the minIterationDuration one.

Indeed what you see is what is expected.

That said, as you found out, this would work and apply the same minIterationDuration value to all scenarios:

import http from 'k6/http';
import exec from 'k6/execution';

export const options = {
    discardResponseBodies: true,
    minIterationDuration: '6s',
    scenarios: {
        contacts: {
            executor: 'constant-vus',
            vus: 2,
            duration: '10s',
            exec: 'contacts',
        },
        another: {
            executor: 'constant-vus',
            vus: 2,
            duration: '10s',
            exec: 'news',
        },
    },
};

export function contacts() {
    console.log("[Contacts] VU: ", exec.vu.idInTest, ", time now is " + new Date().toISOString() + "");
    http.get('https://test.k6.io/contacts.php');
}

export function news() {
    console.log("[News] VU: ", exec.vu.idInTest, ", time now is " + new Date().toISOString() + "");
    http.get('https://test.k6.io/news.php');
}

There might be alternative ways to achieve your goal.

For example, a sleep on each function that takes into account the start time of the iteration, and calculates how much time it should still sleep. Or if you are trying to simulate the time a user takes in the browser until the next action, a fixed sleep (or random values between an interval) can also work to make sure requests are not send too fast. Or you could use other executors, like the constant-arrival-rate if what you are after is setting a fixed rate for each request type.

Depending on what is your goal we can advice how to best achieve the requirements. We would need a bit more details.

Cheers!

Hi @eyeveebe,

thanks for your fast response.

I will go with the workaround using the sleep function.

Thank you very much and have a nice week :slight_smile:

1 Like