簡體   English   中英

由於發出過多的Axios請求而導致ENFILE錯誤

[英]ENFILE error due to making too many Axios requests

我有7000個用戶的數組列表。

對於7000個用戶中的每個用戶,我都需要發出GET請求。

我的代碼可以運行,但是很多請求都出現以下錯誤:

"ENFILE"
"ENFILE"
"connect"
"10.10.12.72"
80

我相信我需要限制請求,但不確定如何處理。

這是代碼:

users是7000個條目的數組。

  users.forEach((user) => {
    axios({
      url: getUserRolesEndpoint + `${user.userId}`,
      method: 'get',
      timeout: 10000,
    })
    .then((response) => {
        // I do something with the response
    });
  });

看起來像圖書館的“限制器”解決了我的問題:

 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM