0

My Api to Update Product Details sends 4000 requests at once and waits for a minute and then shows timedout error . please suggest me a good way to handle this issue.

codersha
  • 9
  • 2

1 Answers1

0

Whatever the target is that you're sending these 4000 requests to at once apparently cannot handle that many requests all in flight at the same time and still respond to each request in a timely fashion. This is not surprising.

The usual solution to something like this would be to limit how many simultaneous requests you send to the target to something smaller like 10 or 20 (usually determined with testing). You send 10 requests, then each time a request finishes, you send the next one in line. This way, you never over tax the target server.

You can hand-code code to distribute requests as described above or you can use a pre-built function to do that like Bluebirds Promise.map() or a function like mapConcurrent() and you can see a discussion of this general issue here.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Do you think adding a delay of 250 milli seconds for each request can make this work – codersha Mar 18 '22 at 23:54
  • @codersha - That depends entirely upon the target server and how it is coded and how long a typical request takes to respond. Strict spacing in time (with a timer) will control requests/second, but will not necessarily control how many requests are in-flight at the same time which is also often relevant. – jfriend00 Mar 18 '22 at 23:57