用于Node js连接管理的AWS-SDK



aws-sdk for node js通过内部池管理它的连接吗?

他们的文档让我相信这一点。

httpOptions (map) -传递给底层HTTP的一组选项请求。目前支持的选项有:

proxy [String] -通过代理发送代理请求的URL。代理,https。-执行HTTP请求的代理对象。使用用于连接池。默认为全局代理(http.globalAgent)用于非ssl连接。注意,对于SSL连接时,使用一个特殊的Agent对象来启用peer证书验证。此特性仅在node . js环境。

但是没有办法,至少我找不到,可以让我定义任何连接池属性

如果我想控制正在使用的并发连接,我有什么选择?

让SDK处理这个更好吗?

可以给出http。代理,设置你想要的最大套接字数

var AWS = require('aws-sdk');
var http = require('http');
AWS.config.update({
  httpOptions: {
    agent: new http.Agent(...)
  }
})

我一直在研究这个问题。

我查了一下,找出了使用的默认值。

AWS-SDK使用节点http模块,其中defaultSocketCountINFINITY

他们正在使用https模块,maxSocketCount50

相关代码段。

sslAgent: function sslAgent() {
    var https = require('https');
    if (!AWS.NodeHttpClient.sslAgent) {
      AWS.NodeHttpClient.sslAgent = new https.Agent({rejectUnauthorized: true});
      AWS.NodeHttpClient.sslAgent.setMaxListeners(0);
      // delegate maxSockets to globalAgent, set a default limit of 50 if current value is Infinity.
      // Users can bypass this default by supplying their own Agent as part of SDK configuration.
      Object.defineProperty(AWS.NodeHttpClient.sslAgent, 'maxSockets', {
        enumerable: true,
        get: function() {
          var defaultMaxSockets = 50;
          var globalAgent = https.globalAgent;
          if (globalAgent && globalAgent.maxSockets !== Infinity && typeof globalAgent.maxSockets === 'number') {
            return globalAgent.maxSockets;
          }
          return defaultMaxSockets;
        }
      });
    }
    return AWS.NodeHttpClient.sslAgent;
  }

要操作套接字计数,请参见BretzL的回答。

但是现在有办法同时为httphttps设置代理。您可以通过在从http切换到https时更新配置来解决这个问题,反之亦然。

参见:https://github.com/aws/aws-sdk-js/issues/1185

最新更新