Hi @k6jonne,
As far as I understand you want to load a file from disk that will be some representation of an array. And have VUs take one element from the array?
Depending on whether you are fine with either having as many VUs as elements in the array or VU getting a fixed amount of rows instead of each VU getting the “next” unused element, k6 can help you … or not currently.
If you are fine with that you can use the __VU which goes from 1 to the maximum number of VUs in the instance [1](see at bottom of post).
The basic code will be something like:
var data = JSON.parse(open("./file.json")); // this is the array as json
const maxVUs = 10; // this can be data.length;
var let options = {
duration: "10m",
vus: maxVUS,
}
export default function() {
var el = data[__VU-1]; // maxVUs is data.length
// else you can do some simple math using __ITER and __VU to
// get the next element for each iteration and
// either loop over the array or sleep when the last element is used.
// do something with el
}
If neither of this is fine with you - you likely need this - I highly recommend reading the whole thread especially the comments after that.
Hope this helps you and that I don’t have any script errors ;).
[1] This is not shared between instances in the k6 cloud and you will have problems if you use arrival rate and have preallocatedVUs smaller then maxVUs … as k6 will only allocate more then the preallocatedVUs once you need them which means that you will first run with only preallocatedVUs and then they will increase.