[英]ENFILE error due to making too many Axios requests
I have an array list of 7000 users. 我有7000个用户的数组列表。
For each of the 7000 users, I need to make a GET request. 对于7000个用户中的每个用户,我都需要发出GET请求。
My code runs but I am getting the following error for a lot of the requests: 我的代码可以运行,但是很多请求都出现以下错误:
"ENFILE"
"ENFILE"
"connect"
"10.10.12.72"
80
I believe I need to throttle the requests but not sure exactly how to go about it. 我相信我需要限制请求,但不确定如何处理。
Here's the code: 这是代码:
users is an array of 7000 entries. users是7000个条目的数组。
users.forEach((user) => {
axios({
url: getUserRolesEndpoint + `${user.userId}`,
method: 'get',
timeout: 10000,
})
.then((response) => {
// I do something with the response
});
});
Looks like the libary 'limiter' fixed my issue: 看起来像图书馆的“限制器”解决了我的问题:
const RateLimiter = require('limiter').RateLimiter;
const limiter = new RateLimiter(5, 'second');
users.forEach((user) => {
limiter.removeTokens(1, (errd, remainingRequests) => {
axios({
url: getUserRolesEndpoint + `${user.userId}`,
method: 'get',
timeout: 10000,
})
.then((response) => {
// I do something with the response
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.