Issue with making constant request in k6

I have situation where I need to make constant request for a certain period of time, say 5 requests in every 1 second for 30 seconds. I used the constant-arrival-rate to achieve this but I don’t see the expectations are met while using it. I am expecting 150 requests to be made when the test run finishes but I see less than 150 requests are made. I tried increasing the VUs and still the total requests made does not reach upto 150. Can someone help me out on this? Am I missing something?

scenarios: {
constant_request_rate: {
  executor: 'constant-arrival-rate',
  rate: 5,
  timeUnit: '1s', // 1000 iterations per second, i.e. 1000 RPS
  duration: '30s',
  preAllocatedVUs: 1, // how large the initial pool of VUs would be
  maxVUs: 10, // if the preAllocatedVUs are not enough, we can initialize more
}}

In order to not have any dropped iterations while k6 is initializing VUs mid-test, ensure that you have enough preAllocatedVUs configured in the scenario to be able to run all of your iterations. The exact amount depends on how fast each iteration takes to execute (and free up its VU), but in general it’s best to leave a comfortable margin. Take this script for example:

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

export const options = {
    scenarios: {
        constant_request_rate: {
            executor: 'constant-arrival-rate',
            rate: 5,
            timeUnit: '1s',
            duration: '30s',
            preAllocatedVUs: 50,
        }
    }
}

export default function () {
    console.log(`[t=${(new Date()) - exec.scenario.startTime}ms] iteration ${exec.scenario.iterationInTest}`);
    http.get('https://httpbin.test.k6.io/anything');
}

It’s going to do 150-151 iterations (and requests) and log when each of the iterations starts.

1 Like

@ned Thanks for the reply. It helped me a lot.