add k6 benchmark script

This commit is contained in:
Adien Akhmad 2025-11-19 18:06:34 +07:00
parent deb8c49354
commit 0e871aeffa
4 changed files with 12239 additions and 0 deletions

41
bench-fuzzy.js Normal file
View file

@ -0,0 +1,41 @@
import http from "k6/http";
import { check } from "k6";
import { SharedArray } from "k6/data";
export const options = {
discardResponseBodies: true,
scenarios: {
concurrent_test: {
executor: "per-vu-iterations",
vus: 1,
iterations: 1,
maxDuration: "30m",
},
},
};
const testData = new SharedArray("test requests", function () {
return JSON.parse(open("fuzzy.json"));
});
export default function () {
console.log(`Starting run with ${testData.length} requests.`);
for (const requestBody of testData) {
const url = "http://localhost:7007/api/image/generate";
const payload = JSON.stringify(requestBody);
const params = {
headers: {
"Content-Type": "application/json",
Accept: "image/png",
},
timeout: "200s",
};
const res = http.post(url, payload, params);
check(res, {
[`status is 200 (OK)`]: (r) => r.status === 200,
[`content-type is image/png`]: (r) =>
r.headers["Content-Type"] === "image/png",
});
}
}