So we have basically migrated from JMeter and we mostly used to run the script using per-vu-iteration in JMeter. So 1 row of data in CSV was specific to that VU and each iteration will have the same VU data.
We are able to achieve the same in K6 without any issues. We used __VU or vu.idInTest to get the unique VU and assign row data from CSV to that VU. As a result for any number of iterations VU always hold same data.
Now we want to achieve the same through multiple scenarios in k6. So for now we have defined 2 scenarios and 2 test data file. For 1st scenario VU count is 50. For 2nd scenario VU count is 150. I have provided 2 different CSV’s 1 for Scenario 1 and other for Scenario 2.
Now when I trigger scenarios 1st issue is that vu.idInTest is not specific to scenario but a global variable hence VU count is going upto 200 (Combining both scenarios VU). This causes out of bound array exception in script when reading row data. As 1 csv has 50 rows and other CSV has 150 rows.
Another solution we can think of is having single csv with 200 rows of data. But our data is grouped based on tenant. So suppose for scenario 1 we have csv with 50 rows so every 5 users belong to 1 tenant. As a result we can’t let K6 randomly choose any 50 rows for running Scenario 1 as it will not give equal distribution of load per tenant.
What we were looking for is a way to get __VU or vu.idInTest variable per scenario. So for scenario 1 VU or vu.idInTest will give count from 1-50 and for Scenario 2 VU or vu.idInTest will give from 1-150. Or any other variable which supports this behavior.
Hello @anshulgoel2 From k6 documentation idInTest is global unique across the test run so to achieve your objective you can use iterationInScenario
The identifier of the iteration in the current scenario for this VU. This is only unique for current VU and scenario it is currently executing
Ref: k6/execution | Grafana k6 documentation
Thanks @bandorko already tried this approach. Problem with this approach is that there will be repetition of data for vu. So if I use %50 then 1, 51, 101 and 151 will yield the same result. And if Scenario 1 gets these VU’s assigned then it will run 4 times with same data. Which we don’t want
Hello @Elibarick, tried using iterationInScenario and there are 2 issues with it. 1 is that I need count from 1-50 for Scenario 1. iterationInScenario is always giving it 0 for 0th iteration. 2nd issue is that if iteration count is higher then the value goes beyond 50 and 150.
@anshulgoel2 : If your VU-s doesn’t store data between two iterations, then you could try scenario.iterationInTest % 50 and scenario.iterationInTest % 150. With this aproach the VU will get different id in every iterations from the 0-49 range, but every id wil run the desired times.
My other idea is to use the xk6-atomic extension to assign an incremental unique id to every vu.
Thanks @bandorko scenario.iterationInTest looks more promising. I have run some initial tests and seems like %50 and %150 should help in getting 0-50 and 0-150 range for each scenario separately.
Let me integrate it in my main script and see how it goes.
Problem with this approach is that there will be repetition of data for vu. So if I use %50 then 1, 51, 101 and 151 will yield the same result. And if Scenario 1 gets these VU’s assigned then it will run 4 times with same data. Which we don’t want
@anshulgoel2, couldn’t you use the combination of that strategy and the scenario variable from the k6/execution package to determine what file and row use as a reference to get data from?
EDIT: I see, in such case you would still need to have some sort of dynamic programming, and thus still require a solution like xk6-atomic.
If your concern is that a VU could be reused for both scenarios, and thus could “collide”, then using scenario.iterationInTest (or alternatively using xk6-atomic) I think should work to “evenly distribute” the data.