I want to send 20 requests within 1 second. I’ve tried several methods so far, but the script only executes what is possible within that time frame, like 4 requests within 1 second, and the other 16 are dropped. My requirement is to send 20 requests within 1 second no matter what and log the response status for each request to verify its status. how can I achieve that?
Hi @malitthh
Welcome to the community forum
You created the topic under the k6-browser category, so I’m unsure of the use case. It would help if you could share a (sanitized) script so we can better understand your concrete issue.
It can also help if you share the full output you get when executing your script.
If this is unrelated to the browser, it’s also interesting to know what type of executor you chose. Are you using a constant-arrival-rate
executor?
Thanks for the additional info.
Cheers!
Hi @eyeveebee,
this is the script and the scenario I’m using,
import http from "k6/http";
import { check } from "k6";
export const options = {
thresholds: {
http_req_duration: ["p(95)<7000"], //95% of the requests must finish within 3s
http_req_duration: ["p(75)<9500"], //75% of the requests must finish within 1.5s
checks: ["rate>0.95"], //99% pass rate
http_req_failed: ["rate<0.1"],
},
noConnectionReuse: true,
scenarios: {
constant_scenario: {
executor: 'per-vu-iterations',
vus: 20,
iterations: 1,
maxDuration: '1s',
}
}
};
export default function () {
let data = {
Data: "test data",
DEPARTMENT: "Logistic",
LOCATION: "lka",
SOURCEID: "111A1AaA-1111-11A1-11A1-1111111111",
TEST_PDF_ID: "765765886543"
};
const params = {
headers: {
"Content-Type": "application/json",
Accept: "*/*",
Token: "abctrhsdkdflsdjfsdiukghushfiuesfsef==",
},
};
const url = "https://api.test/abc-service/api/v1/text";
const res = http.post(url, JSON.stringify(data), params);
const req = JSON.parse(res.body);
console.log(req.request_id, res.status);
// check(res, {
// "is status 202": (rs) => rs.status === 202,
// });
}
I’ve tried different methods and ways, but so far, nothing has worked. Every time k6 executes what’s possible within that time range (1sec) , and other requests go into the ‘dropped iteration’ category.
Hi @malitthh
Thanks for sharing the script.
What we see in the output is that the dropped iterations are 16. One reason for this can be that k6 considers that in 1 second, those will not finish and drops them. With maxDuration
being 1 second, k6 might decide it won’t execute all of them. And ends up executing the 4 you see.
You could try increasing the duration, but that might not solve your requirement, to send 20 requests per second.
Have you tried with a constant arrival rate executor? If you define a rate
of 20 with a timeUnit
of 1 second, with the duration you want to keep this rate for, and enough preAllocatedVUs
so k6 can sustain the rate (this will depend on the latency of your endpoint https://api.test/abc-service/api/v1/text), you might get the load you need.
I hope this helps
Thank you, will try that