Http.batch or http.request

Hey k6 people,

I am new to k6 and just load testing in general. I am trying to create a spike test to test multiple API endpoints. The goal is to see how my system behaves if there is suddenly huge load on all endpoints.
So far everything seems to be working fine however i’m not quite sure if I should use http.request or http.batch - like what the right approach is(?) I want the test to mimic a real scenario where lots of users request data at the same time.

My understanding of http.batch is that it is used for testing multiple endpoints that are related - similar to how a web browser would load a website, its css, scripts and whatnot.
But would it make sense to use it for endpoints that aren’t really related and would that be “realistic”?
Or should I rather loop over my endpoints and call http.request for each of them separately.
I hope I am making sense otherwise please let me know and I’ll try to elborate better.

I have tried to look up examples of how to test multiple API endpoints at the same time, but haven’t had any luck so far, so if anyone knows a place to look please feel free to share.

Thanks in advance.

Hi @agan

Sorry for the delay, and a warm welcome to the community forums! :wave:

I’d say that you’re doing right. In that case, parallelism is happening since multiple VUs are running simultaneously. The batch is probably a better fit for the cases when the same user sends parallel requests (let’s say static HTML, CSS, and JS).

Let me know if that answers,

Hi @olegbespalov,

Thanks for your reply!

I made some changes to my script and along with that did some more research on the topic and decided that http.request was the proper way to go for my case :blush:

1 Like