From 540c2936c886660feadb6230ba90f31b9b5f86f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Fern=C3=A1ndez?= Date: Fri, 2 Dec 2016 21:06:38 +0100 Subject: [PATCH] Add support to max network concurrent requests --- src/cli/index.js | 2 ++ src/config.js | 3 +++ src/util/request-manager.js | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/src/cli/index.js b/src/cli/index.js index fe5cd6f353..8383c7279c 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -80,6 +80,7 @@ commander.option( '--no-progress', 'disable progress bar', ); +commander.option('--network-concurrency ', 'maximum number of concurrent network requests'); // get command name let commandName: ?string = args.shift() || ''; @@ -360,6 +361,7 @@ config.init({ production: commander.production, httpProxy: commander.proxy, httpsProxy: commander.httpsProxy, + networkConcurrency: commander.networkConcurrency, commandName, }).then(() => { const exit = () => { diff --git a/src/config.js b/src/config.js index 426653b1d1..9ccc90239e 100644 --- a/src/config.js +++ b/src/config.js @@ -34,6 +34,7 @@ export type ConfigOptions = { cafile?: ?string, production?: boolean, binLinks?: boolean, + networkConcurrency?: number, // Loosely compare semver for invalid cases like "0.01.0" looseSemver?: ?boolean, @@ -202,6 +203,8 @@ export default class Config { cafile: String(opts.cafile || this.getOption('cafile') || ''), cert: String(opts.cert || this.getOption('cert') || ''), key: String(opts.key || this.getOption('key') || ''), + networkConcurrency: Number(opts.networkConcurrency || this.getOption('network-concurrency') || + constants.NETWORK_CONCURRENCY), }); } diff --git a/src/util/request-manager.js b/src/util/request-manager.js index ebc0285c0d..e0e134a2bf 100644 --- a/src/util/request-manager.js +++ b/src/util/request-manager.js @@ -42,6 +42,7 @@ type RequestParams = { encoding?: ?string, ca?: Array, cert?: string, + networkConcurrency?: number, key?: string, forever?: boolean, strictSSL?: boolean, @@ -114,6 +115,7 @@ export default class RequestManager { ca?: Array, cafile?: string, cert?: string, + networkConcurrency?: number, key?: string, }) { if (opts.userAgent != null) { @@ -144,6 +146,10 @@ export default class RequestManager { this.ca = opts.ca; } + if (opts.networkConcurrency != null) { + this.max = opts.networkConcurrency; + } + if (opts.cafile != null && opts.cafile != '') { // The CA bundle file can contain one or more certificates with comments/text between each PEM block. // tls.connect wants an array of certificates without any comments/text, so we need to split the string