Hi! I need to create a load test where huge, ~1GB size data files have to be used as input for POST request payload. Each line in these file would be a JSON object and pre-read into an array and the test should run the following way:
- requests have to be sent at a constant rate, so constant_request_rate scenario will be used
- each request should send the next JSON object from the array as a payload
As i understand every VU will share the data so this will also add to the complexitiy.
How would you solve the problem to read the next item from the array and use it as a payload for the current request? Maybe it’s a JS question, but im new to k6 and JS as well and as i see the default function cannot store state, like index of an array defined outside of it.
I got this far
import http from "k6/http";
import { SharedArray } from "k6";
export let options = {
scenarios: {
constant_request_rate: {
executor: 'constant-arrival-rate',
rate: 10,
timeUnit: '3s',
duration: '60s',
preAllocatedVUs: 10,
maxVUs: 20,
},
},
};
const data = new SharedArray("some data name", function() { return open("./payload.txt").split(/\r?\n/); });
export default function () {
???
}