Distribution of RPM with multi scenarios

We are running multiple scenarios in a constant arrival rate executor (RPM) script.

Is there was an easy way in k6 to distribute the total requests between the different scenarios in the script( for example if we have 2 scenarios and wanted to distribute the total requests in a 70/30 ratio )

K6 does not do that natively but I vaguely remember there was a hack to achieve it. You’ll have to search it in the community.

I did search the community the closet thing was to distribute VUs not Requests and that solution cannot be applied with the multi scenarios and requests. If you can direct me to any other solution that would be great.

Somebody from K6 teams needs to guide you on this. You could try Locust. This tool does that natively

Hi @ritman, welcome to the community forum:tada:!

Can you expand on your usecase? and why distributing iteration especially with arrival rate will be not be sufficient for your use case.

The usecase we have is -

500 requests per min
70% of requests should retrieve data ( GET requests )
30% of requests should write data ( POST requests)

Hence we are using arrival rate executor
but we need to still distribute the requests in the desired ratio

but we need to still distribute the requests in the desired ratio

you have not shown what you have tried and why it hasn’t worked, but here are two options:

export const options = { 
  scenarios: {
    one: {   
       executor: 'constant-arrival-rate',
         duration: '30m',
         rate: 150, // 30% of 500
         timeUnit: '1m',
         preAllocatedVUs: 50,
         exec: "postFunction"
    },
    two: {   
       executor: 'constant-arrival-rate',
         duration: '30m',
         rate: 350,//70% of 500
         timeUnit: '1m',
         preAllocatedVUs: 50,
         exec: "getFunction"
    }, 
  }
}

export function postFunction() {
  // do your post stuff
} 

export function getFunction() {
  // do your get stuff
} 

Arguably this is the better option as you have two separate scenarios and the configuration shows what your intention

or with one scenario and using modulo operator - more or less how it was done before scenarios existed:

import exec from "k6/execution";
export const options = { 
  scenarios: {
    one: {   
       executor: 'constant-arrival-rate',
         duration: '30m',
         rate: 500,
         timeUnit: '1m',
         preAllocatedVUs: 50,
    },
}
export default function () {
   if (exec.scenario.IterationInScenario % 10 <3) {
     postFunction();
   } else {
     getFunction();
   } 
}
export function postFunction() { // this doesn't need to be exported
  // do your post stuff
} 

export function getFunction() { // this also doesn't need to be export
  // do your get stuff
} 

Hope this helps you, and please tell us what you actually tried when you are explaining something doesn’t work.

Thx for your suggestions …
I had tried the first method and have a variable that calculates the rate based on the number of requests through an env variable. It an approx as will have to round the number based on the requests. Will try the second method as well …