Iterate CSV file records only once

Hello, I have a csv with records which can be used only 1 time. Once a record was used it becomes unuseful due it changes its original state.
So, I need help in k6 to iterate a CSV using each record only once, having more than 1 VU?
I’m using papaparse and a ShareArray object to load and store the CSV records.

Thanks

It is a tricky one. If you know JMeter you would know that it handles csv with no problem. Next request is simply taking next record form your csv and you don’t have to worry which user uses what record and you know that each record can be used only once.
Papaparse provides you a “list”. The solution, or a workaround, I came up with was math. :smiley: It can be adjusted to your specific type of run (stages, iterations, duration…).
K6 provides you two crucial things: __VU and __ITER (see definition here). K6 is running async requests so it is troublesome to handle csv like JMeter does. What I came up with is this:
Let assume we have 100 records and we want to run 9 VU. VUs are numbered from 1 and ITERs are numbered starting from 0. So:
VU 1 will take records 0-10,
VU 2 will take records 11-21,
…,
VU 9 will take records 88-98.

let maxIter = 11 // you should pass that value while running the test, it is maximum number of records a single VU can use
if (__ITER < maxIter) {
    record = csvData[(__VU - 1) * maxIter + __ITER]
    *request using record*
}

The downsize is each VU makes up to 11 requests. Maybe I will inspire you and you will change it to something better. :slight_smile: