I’m testing a dasboard in my job that makes some parallel calls to the backend, I checked that in Chrome dev tools. Is it a bad idea to make those calls with http.asyncRequest, and put it in a Promise.all() method? Or do i do that in the “normal way” using http.get()?
I don’t know if it impacts in the metrics that I measure since Promise.all will return the results when all the promises got fulfilled or 1 got rejected.
Hey @gabbrieu
Welcome on the support forum I’ll do my best to try and help
From what you describe, I believe you should be perfectly fine using the http.asyncRequest
indeed. k6 collects samples and feeds metrics in a way that should be independent from the runtime (synchronous vs asynchronous).
I would suggest you give it a shot, and let us know how that worked out. If you experience further issues with it, I’ll be happy to help
Hey @oleiade,
Thank you for your greetings and answer, i’ll try it and let you know if i had a problem.
I have another question: if i use asyncRequest i will get any advantage or disadvantage in my tests?
I saw the use of Promise.race() in the examples to catch the first task to complete, but i’m asking in terms of speed or any kind of advantages, or maybe disavantages of using asyncRequest in my tests.
You’re very welcome
TL;DR: we don’t anticipate that asynchrnous code impact the performance of your script.
That’s a good question, to which I don’t necessarily have a definite and universal answer to. I would tend to say the benefits are somewhat similar to what you observe in any other JavaScript runtime: making the long-living or IO heavy tasks non-blocking in a way that let’s the runtime do other things while waiting. Regarding the downsides I can’t really think of one on top of my head now that k6 supports the async/await
syntax.
It would be really hard to say if you would observe drastic performance impacts, because it really depends on the script you write. But in general, you should be on the safe side using asynchronous code; especially now that we support the async/await
syntax.
With k6 being a performance testing tool at its core, It should be somewhat easy to verify that assumption with your specific script. Run the script with synchronous code a couple of times, take note of the performance report (you might want to pay specific attention to the iteration duration for instance), do the same with its asynchronous counterpart, and compare.
Let us know how that goes
1 Like