Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to max network concurrent requests #2129

Merged
merged 1 commit into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ commander.option(
'--no-progress',
'disable progress bar',
);
commander.option('--network-concurrency <number>', 'maximum number of concurrent network requests');

// get command name
let commandName: ?string = args.shift() || '';
Expand Down Expand Up @@ -360,6 +361,7 @@ config.init({
production: commander.production,
httpProxy: commander.proxy,
httpsProxy: commander.httpsProxy,
networkConcurrency: commander.networkConcurrency,
commandName,
}).then(() => {
const exit = () => {
Expand Down
3 changes: 3 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
});
}

Expand Down
6 changes: 6 additions & 0 deletions src/util/request-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type RequestParams<T> = {
encoding?: ?string,
ca?: Array<string>,
cert?: string,
networkConcurrency?: number,
key?: string,
forever?: boolean,
strictSSL?: boolean,
Expand Down Expand Up @@ -114,6 +115,7 @@ export default class RequestManager {
ca?: Array<string>,
cafile?: string,
cert?: string,
networkConcurrency?: number,
key?: string,
}) {
if (opts.userAgent != null) {
Expand Down Expand Up @@ -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
Expand Down