简体   繁体   English

nodejs 中的多个 Api 请求给出超时错误

[英]Multiple Api requests in nodejs gives Timedout error

My Api to Update Product Details sends 4000 requests at once and waits for a minute and then shows timedout error.我的更新产品详细信息的 Api 一次发送 4000 个请求并等待一分钟,然后显示超时错误。 please suggest me a good way to handle this issue.请给我一个处理这个问题的好方法。

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.无论目标是什么,您一次发送这 4000 个请求显然无法同时处理这么多请求,并且仍然及时响应每个请求。 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).此类问题的通常解决方案是将同时发送到目标的请求数限制为更小的值,例如 10 或 20(通常通过测试确定)。 You send 10 requests, then each time a request finishes, you send the next one in line.您发送 10 个请求,然后每次请求完成时,您发送下一个请求。 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 .您可以手动编写代码以如上所述分发请求,或者您可以使用预构建的 function 来执行此操作,例如 Bluebirds Promise.map()或 function(例如mapConcurrent()) ,您可以在此处看到对这个一般问题的讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM