Duration of k6 run with HTTP retry requests

I have a scenario where I am making 2000 concurrent requests. If any of these return a 429, I am retrying the request after a few seconds. I make a maximum of 3 retries for each request so that the request might finally become a 200
What I want to know is:
1> If the run will end as soon as the 2000 concurrent requests are complete? Or Will it wait for these retry requests?
2> Do the retry requests have their own VU? Though in utils I have options as {vus: 2000, iterations: 2000}
3> Can I add a sleep of say 5s before each retry? This is so that the system that we are hitting has some time to free up resources before we make a request again.
If I add a sleep, will the k6 run wait for these retried requests or just end once the 2000 concurrent requests are done?
4> Is there any way to run 2000 concurrent requests, then wait for the retried requests to complete on their own?


I think you have some misconceptions about how k6 works, so I’ll provide some background and hopefully answer all your questions.

Think about each VU as a standalone, well, virtual user of your service. The VU’s only purpose is to execute the script’s default function (or a custom function you can specify with the exec option after v0.27.0), so whatever requests you make in that function will be done by each separate VU. k6 doesn’t make a distinction between initial and “retried” requests, that’s up to your script logic to determine. So your retried requests will be made by the same VU that makes the initial ones.

With the configuration {vus: 2000, iterations: 2000} each VU will run a single default iteration, so k6 will wait until all requests complete.

Can I add a sleep of say 5s before each retry?

Sure, since execution is based on iterations, not requests, you can use sleep(), and k6 will wait for it just as if it was a long-running request.

I’m not sure what you mean with “on their own” in the last question. Like I mentioned above, k6 doesn’t make a distinction between initial and retried requests, so both will be executed in the same VU.

Also, take a look at the gracefulStop and gracefulRampDown options in versions v0.27.0 and above that you can use in more advanced scenarios.



1 Like

Thanks for the detailed explanation Ivan. This helps clear the questions I had.