From 6933e00b6ce1a44993d45602f0e1641e295450f1 Mon Sep 17 00:00:00 2001 From: rickyes Date: Thu, 28 May 2020 23:15:55 +0800 Subject: [PATCH 1/2] http: add maxTotalSockets to agent class Add maxTotalSockets to determine how many sockets an agent can open. Unlike maxSockets, The maxTotalSockets does not count by per origin. PR-URL: https://github.com/nodejs/node/pull/33617 Fixes: https://github.com/nodejs/node/issues/31942 Reviewed-By: Robert Nagy Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- doc/api/http.md | 10 ++ lib/_http_agent.js | 58 ++++++++- .../test-http-agent-maxtotalsockets.js | 113 ++++++++++++++++++ 3 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 test/parallel/test-http-agent-maxtotalsockets.js diff --git a/doc/api/http.md b/doc/api/http.md index d7e8c4caa852f1..88949e697f7b83 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -285,6 +285,16 @@ added: v0.3.6 By default set to `Infinity`. Determines how many concurrent sockets the agent can have open per origin. Origin is the returned value of [`agent.getName()`][]. +### `agent.maxTotalSockets` + + +* {number} + +By default set to `Infinity`. Determines how many concurrent sockets the agent +can have open. Unlike `maxSockets`, this parameter applies across all origins. + ### `agent.requests` * `options` {Object} Set of configurable options to set on the agent. @@ -131,6 +135,10 @@ added: v0.3.4 * `maxSockets` {number} Maximum number of sockets to allow per host. Each request will use a new socket until the maximum is reached. **Default:** `Infinity`. + * `maxTotalSockets` {number} Maximum number of sockets allowed for + all hosts in total. Each request will use a new socket + until the maximum is reached. + **Default:** `Infinity`. * `maxFreeSockets` {number} Maximum number of sockets to leave open in a free state. Only relevant if `keepAlive` is set to `true`. **Default:** `256`.