几个月来,我一直在使用 Axios 调用内部 API (Apache)。这平均产生了大约 3k 个简单的 GET
请求,以便为每个请求检索一些 JSON 记录。
我使用 axios
发送请求(通过代理),并使用 Bluebird
同时执行此操作。
这是一些示例代码。
const results = await Bluebird.map(urls, function (url) {
const promise = axios.get(url, {
proxy: {
host: parsedFixieUrl.hostname,
port: parsedFixieUrl.port,
auth: {
username: username,
password: password
}
},
//This didn't fix the issue
// httpsAgent: new https.Agent({ keepAlive: true })
});
}, { concurrency: 10 });
我正在附加 Rax
以重试请求。
import rax from 'retry-axios';
import axios from 'axios';
const interceptorId = rax.attach(axios);
这在一段时间内效果很好。就在最近,urls
的数量增加了约 130(所以 <5%)。现在 - 我收到了 socket hangup error
Error: socket hang up at createHangUpError (_http_client.js:331:15) at Socket.socketOnEnd (_http_client.js:423:23)
code: 'ECONNRESET'
这里有一些关于 Rax
的有趣内容
raxConfig:
{ currentRetryAttempt: 2,
retry: 3,
retryDelay: 100,
instance: [Object],
backoffType: 'exponential',
httpMethodsToRetry: [Array],
noResponseRetries: 2,
statusCodesToRetry: [Array] },
data: undefined },
所以,它似乎在重试时失败了。
回顾堆栈跟踪,我认为是客户端 (axios) 挂断了套接字,因为它没有得到服务器的响应。
https://searchcode.com/codesearch/view/89235658/
增加并发并添加 keepAlive:true
(如其他帖子建议的那样)没有解决任何问题。
stacktrace 还提供了失败的 url。 GET
设置这个单独的网址本身可以立即生效。所以,我认为问题在于请求量和并发性。
奇怪的是,将请求量增加 <5% 会使事情不起作用。
有关如何了解更多信息和/或解决此问题的任何想法?我还不知道 httpd.conf
中关于 maxConnections
等的参数。
我想知道这是否可以在 Axios
方面解决。
谢谢!