Using k6's http.batch to send parallel requests in a single VU
Learn how k6’s http.batch lets a single virtual user send multiple HTTP requests in parallel, with a worked example, trade‑offs, and verification steps.
10 Jun 2026, 17:14 UTC

Why batch requests matter
When writing a load test you often need a virtual user (VU) to perform several actions at the same time, such as loading a page and fetching its associated API calls. Without a built‑in way to run those requests in parallel, you either increase the VU count (which adds overhead) or serialize the calls, which can under‑represent real‑world concurrency. k6’s http.batch API, available since v0.30, lets a single VU fire multiple HTTP requests simultaneously within one iteration, returning responses in the same order as the input array.
Worked example: two GETs to httpbin.org
The following script creates a batch of two GET requests, logs each status code, and asserts that both are successful.
import http from 'k6/http';\nimport { check, sleep } from 'k6';\n\nexport const options = {\n vus: 5,\n duration: '30s',\n};\n\nexport default function () {\n const batch = [\n { method: 'GET', url: 'https://httpbin.org/get' },\n { method: 'GET', url: 'https://httpbin.org/get' },\n ];\n const responses = http.batch(batch);\n \n responses.forEach((res, i) => {\n check(res, {\n [`batch request ${i + 1} status 200`]: (r) => r.status === 200,\n });\n });\n \n // optional think‑time between iterations\n sleep(1);\n}\nSave the file as batch_test.js and run it with a recent k6 binary:
k6 run batch_test.js\nYou should see two entries per iteration in the output, for example:
✓ batch request 1 status 200\n✓ batch request 2 status 200\nThe execution summary will show http_reqs equal to batch size × iterations. If you ran the script with 5 VUs for 30 seconds and each iteration takes roughly 1 second (the sleep), you would expect about 150 iterations, thus roughly 300 HTTP requests.
Trade‑offs and practical checks
- Think‑time is not additive: because the requests are dispatched at the same moment, the delay between them inside the batch is zero. If your real user pauses between actions, you must model that pause outside the batch (e.g., with
sleep) to avoid under‑representing pacing. - Burst size: a large batch can create a traffic spike that differs from a steady ramp‑up. Start with a modest size (2‑4) and increase only after confirming the target can handle the burst.
- Version requirement:
http.batchwas added in k6 v0.30. Running the script on an older version throwsTypeError: http.batch is not a function. Verify your binary withk6 versionbefore executing.
To confirm the batch executed in parallel, examine the per‑iteration timestamps in the detailed output (if you enable --out with a format that includes timestamps) or simply check that the http_reqs metric matches the expected count as described above.
When to choose http.batch over more VUs
Use http.batch when you want to simulate a user performing several simultaneous actions without inflating the VU count, which reduces memory and CPU overhead in the test generator. If the goal is to ramp up overall load on the system under test, increasing VUs remains the primary lever; http.batch is complementary for intra‑user concurrency.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.