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

Speedup fetch step by limiting concurrency on network requests only #1182

Merged
merged 2 commits into from
Apr 10, 2020
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
30 changes: 30 additions & 0 deletions .yarn/versions/f234e0b0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
releases:
"@yarnpkg/cli": prerelease
"@yarnpkg/core": prerelease

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-node-modules"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/pnpify"
5 changes: 2 additions & 3 deletions packages/yarnpkg-core/sources/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,12 @@ export class Project {
return structUtils.stringifyLocator(pkg);
}]);

const limit = pLimit(5);
let firstError = false;

const progress = Report.progressViaCounter(locatorHashes.length);
report.reportProgress(progress);

await Promise.all(locatorHashes.map(locatorHash => limit(async () => {
await Promise.all(locatorHashes.map(locatorHash => (async () => {
const pkg = this.storedPackages.get(locatorHash);
if (!pkg)
throw new Error(`Assertion failed: The locator should have been registered`);
Expand All @@ -941,7 +940,7 @@ export class Project {
if (fetchResult.releaseFs) {
fetchResult.releaseFs();
}
}).finally(() => {
})().finally(() => {
progress.tick();
})));

Expand Down
7 changes: 6 additions & 1 deletion packages/yarnpkg-core/sources/httpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import got, {GotOptions, NormalizedOptions, Response} from 'got';
import {Agent as HttpsAgent} from 'https';
import {Agent as HttpAgent} from 'http';
import micromatch from 'micromatch';
import plimit from 'p-limit';
import tunnel, {ProxyOptions} from 'tunnel';
import {URL} from 'url';

import {Configuration} from './Configuration';

const NETWORK_CONCURRENCY = 8;

const limit = plimit(NETWORK_CONCURRENCY);

const cache = new Map<string, Promise<Response<Buffer>>>();

const globalHttpAgent = new HttpAgent({keepAlive: true});
Expand Down Expand Up @@ -101,7 +106,7 @@ export async function request(target: string, body: Body, {configuration, header
hooks: makeHooks(),
});

return gotClient(target) as unknown as Response<any>;
return limit(() => gotClient(target) as unknown as Response<any>);
}

export async function get(target: string, {configuration, json, ...rest}: Options) {
Expand Down