How to distribute VU's across different scenarios with k6

You can use modulo operation (%) to do something like that in your case

if (__VU % 10 == 0) {
// 10% of the VUs
} else if (__VU % 10 <= 3) {
// 30% of the VUs
} else {
// the rest of the VUs (60%)
}

Obviously you can write the three different code blocks as different functions to make it more readable on your default function to be just the code above calling the different functions.

Also in order for the above code to work you should have 10+ VUs and they should be divisable by 10 without remainder. Or you can make it based on the iteration in which case just us e __ITER instead of __VU it will have the same problem but usually iterations are a lot more than VUs so the error should be marginal.

3 Likes