0

I have a rest api backend server (NodeJs/Typescript) to which I am making a post request which return me a response. The thing is that I am trying to use my frontend to make about 8 post request calls at the same time with the same data (weird, I know) but that is the requirement of the project.

Background: When I make one post call at the press of a button and then I refresh the page and press the button again. The backend runs both of those requests in parallel. This is what I want to do. So, I tried changing the front end code to make 5 post request at the call of the button but for some reason these request then get executed in sequence, meaning that I get one response and then the other request starts it execution as opposed to the page refers approach where they all start at the same time.

I want to do this because the server won't get any requests and with this approach I am hoping to get sone sort of parallelization from the node environment.

Ayaz M
  • 11
  • 1

1 Answers1

0

Each browser has a limit to the number or requests that can be fired on the same host - here. When the limit is reached the requests are queued.

John Williams
  • 4,252
  • 2
  • 9
  • 18
  • Thank you for the response. The thing is I have tried making just 3 and 2 request but the result is still the same. Shouldn't 2 or 3 request approach work if this was the case? – Ayaz M Jan 27 '23 at 17:35
  • If 2 requests are sent separately then how do you know they are ever handled in parallel? Can you post the code snippet that makes the calls? – John Williams Jan 27 '23 at 17:38
  • Maybe a async problem ? Without code its hard to guess whats going on. If you fire the POST x times and the function waits for the response from the server this could lead into blocking the loop. – Mahony Production Jan 27 '23 at 17:43
  • I know they are handled in parallel because I have access to the backend and I have logged the information on the server console and I am a 100 % sure that when I a refresh the front end to send another request they are handled in parallel. – Ayaz M Jan 27 '23 at 18:08
  • the thing with the async issue is that the api is not waiting for a response i.e. no await behind the async call. Basically whoever wrote the frontend made a post request to the backend did something like this: `client.post('/myEndPoint/ {bodyHere});`. I am trying to do something similar and the post request that I am making are exactly the same just in a for loop with a timeout of 2 seconds after each iteration. @MahonyProduction – Ayaz M Jan 27 '23 at 18:11