0

I am using native fetch at the google chrome browser. Trying to send multiple API requests to the same domain.

const parallel = 100
Promise.all(Array(parallel).fill('').map(() => fetch(url, {method: 'POST', body: JSON.stringify(data) })))

data variable by itself is about 41802kb.

Debugging network, I realize that Request sent takes the longest time enter image description here

Comparing the same requests but when parallel=10 enter image description here

Anything I can do to improve this? The same behaviour with nodejs using the node-fetch package. Is there any solution to run multiple requests to the same domain in parallel without loosing fast response time?

  • Do you have control of the API, might you be rate limited at 100 requests? A lot of 3rd party API's will rate limit calls to stop a potential DDOS – Jarede Sep 01 '21 at 11:10
  • no, i don't. i have tried to point on my local http server which accepts request and simply respond with http code 200. result the same – Sergii Zinkevych Sep 01 '21 at 12:14
  • https://stackoverflow.com/questions/55973968/how-to-limit-concurrent-parallel-browser-requests-in-chrome#:~:text=Website%20A%20is%20getting%20resources%20from%20its%20own,this%20to%20a%20maximum%20of%2010%20for%20example. I think this will help you... Chrome limits the amount of connections to the same domain. Try running the same test but without chrome – Jarede Sep 01 '21 at 14:44
  • those limitations related to http1. api server which i use supports http2. moreover, in nodejs i have the same – Sergii Zinkevych Sep 01 '21 at 14:47
  • might be worth adding these details into your original post. – Jarede Sep 01 '21 at 15:06
  • Also, not 100% sure the built in fetch API handles HTTP2, you might need a library like https://www.npmjs.com/package/fetch-h2, but as i say i'm not 100% sure – Jarede Sep 01 '21 at 15:13

1 Answers1

0

when you lost fast response time in parallel requests to the same domain, it depends on many factors for example, you should find a bottleneck here,

1 - the internet speed

2 - the API server downstream speed

3 - ratio control and DDoS control on API server

etc ...

for checking the internet speed you could check your bandwidth and deploy some local HTTP server and send parallel requests and compare the result as I know its very rarely the problem was from client code, commonly its depends on items that said

mohammad Naimi
  • 2,259
  • 1
  • 5
  • 15