From 7ae0a4902ba22835ae8dfbe73d2b4b760736e14c 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 | 2 ++ src/util/request-manager.js | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/src/cli/index.js b/src/cli/index.js index fe5cd6f353..f6a832e122 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -80,6 +80,7 @@ commander.option( '--no-progress', 'disable progress bar', ); +commander.option('--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, + concurrency: commander.concurrency, commandName, }).then(() => { const exit = () => { diff --git a/src/config.js b/src/config.js index 426653b1d1..4abde37010 100644 --- a/src/config.js +++ b/src/config.js @@ -34,6 +34,7 @@ export type ConfigOptions = { cafile?: ?string, production?: boolean, binLinks?: boolean, + concurrency?: number, // Loosely compare semver for invalid cases like "0.01.0" looseSemver?: ?boolean, @@ -202,6 +203,7 @@ 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') || ''), + concurrency: Number(opts.concurrency || this.getOption('concurrency') || constants.NETWORK_CONCURRENCY), }); } diff --git a/src/util/request-manager.js b/src/util/request-manager.js index ebc0285c0d..f51da8f5ef 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, + concurrency?: number, key?: string, forever?: boolean, strictSSL?: boolean, @@ -114,6 +115,7 @@ export default class RequestManager { ca?: Array, cafile?: string, cert?: string, + concurrency?: number, key?: string, }) { if (opts.userAgent != null) { @@ -144,6 +146,10 @@ export default class RequestManager { this.ca = opts.ca; } + if (opts.concurrency != null) { + this.max = opts.concurrency; + } + 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