Data parameterisation with unique index

Hi @kaushik, welcome to the forum

First at least for now you will need to have a constant numbers of VUs so your preAllocatedVUs and maxVUs should be the same (and I would argue this should be the case for 99.9% of the users in all situations) as the math is based on the VUs.

If you don’t really care that they are iterated randomly I would recommend going with one of the responses in When parameterizing data, how do I not use the same data more than once in a test?

If you really want randomness I would recommend using something like this. It’s important to note that you will also need to “premap” some values to each VU so if you have 100 values and 10 VUs each VU gets for example a consecutive 10 values so VU 1 gest 1-10, VU2 gets 11-20 and so on(indexes in arrays start from 0 while VUs start from 1 so … you need to work with the math). Alternatively, you might decide that VU 1 get 1, 11,21 and so on while VU 2 gets 2,12,22 and so on. This doesn’t need to actually mean that you have a different array just that those are the values you will want to use in each VU(see example below).

Regardless of the specific way you split data between VUs in the end you will want to somehow get the numbers 1-10 in a random order which is where the above algorithm will come into place for that you need to calculate (a*__ITER + b) % 10 as long as a and 10 and coprime so given that 10 is not prime as long as a is prime and not 2 or 5 you are in the clear and can totally ignore b so for example (7*__ITER)%10 will give you the number 0-9 in the following order 0, 7, 4, 1, 8, 5, 2, 9, 6, 3 and then it will loop to the beginning. With a=3 it will be 0, 3, 6, 9, 2, 5, 8, 1, 4, 7.

If you add b which can be w/e (so even random one that you make at the initialization of VU) you will not start at 0. You can also randomize a to 10 prime numbers so you don’t get the same order and be even more random.

Putting all of this together you get:

var b = Math.floor(Math.random()* 1000) +1 // get b between 1 and 1000
var a = [3,7,9,11,13,17,19,21,23,27][Math.floor(Math.random() *10)] // some of this aren't prime but are coprime with 10

export let options = {
	scenarios: {
		constant_request_rate: {
			executor: "constant-arrival-rate",
			rate: 10,
			duration: "10s",
			preAllocatedVUs: 2,
			maxVUs: 2,
		},
	},
}
export default function () {
	var index  = (a*__ITER + b)%10;
	// var globalIndex = (__VU-1)*10 + index; // for 0-10 for VU 1
	var globalIndex = (index)*10 + __VU; // for 0,10,20 for VU 1
	console.log(`i: ${__ITER}, vu ${__VU}, local index ${index}, global ${globalIndex} `);
}

Hope this helps you