Sequential Data Assignment for VUs in constant-vus Executor

I’m working on a load test scenario in K6 where I need each Virtual User (VU) to process unique data from a CSV file. Here’s what I’ve tried so far:

export const options = {
scenarios: {
functionName: {
executor: “constant-vus”,
exec: “functionName”,
duration: “5s”,
vus: 3, // Number of VUs
},
},
thresholds: {
http_req_duration: [“p(95)<500”],
},
};

let data = itemData[__VU - 1].code;

However, with this setup, I’m noticing that the same data (the first row of the CSV) is being used by all VUs. I want each VU to read a unique row from the dataset so that VU1 gets the first row, VU2 gets the second row, and so on.

Questions:

  1. How can I configure K6 with the constant-vus executor to ensure each VU uses unique data?
  2. Is there a specific executor better suited for this use case?

Any insights or examples would be greatly appreciated! Thank you in advance!

hi @ishitaguptamaersk,

unfortunately in K6 doesn’t have created a function which get sequency value in data.
However in my work I created a way using scenario.iterationInTest which the unique and zero-based sequential number of the current iteration in the scenario. It is unique in all k6 execution modes - in local, cloud and distributed/segmented test runs. However, while every instance will get non-overlapping index values in cloud/distributed tests, they might iterate over them at different speeds, so the values won’t be sequential across them.

Below have code as example:

import { exec, scenario } from "k6/execution";
function sequencyItem(arrayOfItems) {
	return arrayOfItems[scenario.iterationInTest];
}
1 Like