How to have unique data row from a CSV file to be used/assigned for each VU only in k6 Load Testing

My set up is this:

  1. CSV File:
    -201 rows with different values/data each row.

  2. Actual Load Test File:
    *201 VUs
    *Peak Load Stages:

    1m=201VUs,
    3m=201VUs,
    1m=0 VUs.

*No fixed Iteration.
*Duration is 5 minutes

My goal:

I want each VUs to have its own data row from the CSV file, that they will use for all the processes/enpoints in my default function. Then those VUs with their assigned data row will loop concurrently in any number of iteration. So in this way, any VUs will not have any same data to each other fellow VUs while looping. Because as of now, Im getting an error in some of the endpoints since some VUs are sharing same data.

1 data row from CSV = 1 VU

Example :

-Row A is to be used only for Virtual User A --then iterate/loop using the same data (row A)

-Row B is to be used only for Virtual User B --then iterate/loop using the same data (row B)

-Row C is to be used only for Virtual User C --then iterate/loop using the same data (row C)

…and so forth

…each VUs iterating/looping in parallel (as how k6 VUs normally work as far as I know, correct me if I’m wrong.)

Thanks for the help.

Hi @mmm014,

You can see When parameterizing data, how do I not use the same data more than once in a test? - #2 by mark and in your case you need the uniqueNumber to just be __VU-1. edit: you need the -1 as arrays are indexed from 0 but __VU starts from 1.

Hope this helps you

Hi @mstoykov , thanks for reaching out! Upon checking, the sample code given on the link you gave is using JSON file as its external data resource. I am using CSV. Do I need to change something on the sample code for it to be used for CSV? I am using papaparse and shared array btw. Or should I just convert my CSV into JSON for ease of access? Lol. Thanks!

The data source type doesn’t matter here - what’s important is calculating the unique number as that will be the position in the data source we pull the data from.

2 Likes

Thanks @mark @mstoykov. I’m basically new here in k6 so your help means a lot to me. Will check and will try it out. Forgive me if I might update here or ask for some additional inquiries/clarification I might need to confirm. Thank you so much!

I am reading in a CSV file with Papa Parse and it is working well. See here for more info: https://k6.io/docs/examples/data-parameterization/

1 Like