Constant request rate WITH paramerised data?

Hey there! I’m trying to create a scenario whereby four endpoints are queried x times per second for an entire hour, in order to simulate and assess realistic load patterns.

I know that I can use the ‘constant-arrival-rate’ executor to generate the correct number of requests, but I also want to avoid server-side cacheing, so need also to use ‘shared-iterations’. To avoid the cacheing, I can simply use sequential numbering to ‘skip’ an endpoint, but I don’t know if this is possible… Alternatively I could use a CSV file with actual things to search for.

Demo idealised script (with one request instead of four, but they’d all use the same index on each iteration):

import http from "k6/http";
import { group, check, sleep } from "k6";

// Sleep duration between successive requests.
const SLEEP_DURATION = 0.1;

BASE_URL = "API.com"

export default function() {

    group("GET something", () => {
        let url = BASE_URL + `/search?limit=1&skip=` + INDEX;
        let request = http.get(url);
        check(request, {"Status OK": (r) => r.status === 200});
        sleep(SLEEP_DURATION);
    });

}

Current scenario config:

{
  "scenarios": {
    "constant_request_rate": {
      "executor": "constant-arrival-rate",
      "rate": 10,
      "timeUnit": "1s",
      "duration": "60m",
      "preAllocatedVUs": 10,
      "maxVUs": 30
    }
  }
}

Any help would be greatly appreciated!

Thinking about it, another way that could work would be to use Math.random() - would this number be different for each VU?

Sorry for the very late reply :disappointed:

Yes, this number will be different for every call to Math.random(), even in a single iteration.

If you want a unique number for every scenario, you can get that from the k6/execution module, with the scenario.iterationInTest field: https://k6.io/docs/javascript-api/k6-execution/#scenario

Hey @ned, cheers for the reply! That looks like exactly what I’m looking for, thanks :slight_smile: