Is it possible to pass vus value in k6 CLI using constant-vus executor in config.js?

Hello!

I need a flexible configuration for the vus parameter. We plan to integrate the load test into the CI / CD pipeline and pass the vus parameter to the build parameters.

config.js

export let options = {
httpDebug: 'full',
minIterationDuration: '1m',
scenarios: {
    bonus_scenario: {
        executor: 'constant-vus',
        exec: 'place',
        duration: '1m',
        gracefulStop: '0s',
        tags: {my_custom_tag: 'test'},
    },
},
};

I tried to use --vus flag with the following command
k6 run --vus=10 build/app.bundle.js

but the value doesn’t change.

image

The test was executed on k6 v0.32.0

How do I set the vus parameter properly in the CLI ?

When you use scenarios, you can’t use --vus to alter the VUs of a specific scenario. Instead, you can use k6 environment variables to inject a value in the middle of the scenario config, like this:

export let options = {
    httpDebug: 'full',
    minIterationDuration: '1m',
    scenarios: {
        bonus_scenario: {
            executor: 'constant-vus',
            exec: 'place',
            duration: '1m',
            vus: __ENV.MY_VUS,
            gracefulStop: '0s',
            tags: {my_custom_tag: 'test'},
        },
    },
};

And then you can execute k6 run --env MY_VUS=10 zt.js.

Btw, why do you use minIterationDuration: '1m', that seems a bit strange?

2 Likes

@ned , thanks for your help.

I’m using minIterationDuration to override base k6 behaviour. In my test I need to send specific requests count which is equal to vus number and not the maximum possible.

Well, let me point you towards the per-vu-iterations executor that was meant for precisely cases like that :smiley: Per VU iterations

It can simplify your code into this:

export let options = {
    httpDebug: 'full',
    scenarios: {
        bonus_scenario: {
            executor: 'per-vu-iterations',
            exec: 'place',
            vus: __ENV.MY_VUS,
            iterations: 1,
            maxDuration: '1m',
            gracefulStop: '0s',
            tags: {my_custom_tag: 'test'},
        },
    },
};

The big bonus is that you won’t have to wait for a minute for your code to execute, if it can take less time than that for all VUs to finish their iteration.