-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworks the worker pool to be more configurable (#5764)
**What's the problem this PR addresses?** This PR extends @anuragkalia's work in #5636 (it starts from the same commits and builds upon them). - The original implementation was keeping a singleton worker pool - I felt this was problematic since we may enter situations (even if only in tests) where multiple calls to `convertToZip` would want to use different pools. - Converting an archive without using a worker was only possible when the concurrency was completely disabled. This was my idea, but retrospectively it felt better to me to have two settings: one for the concurrency, and another to define whether the concurrency is enabled or not. - Passing all those settings from the various fetchers would have been unwieldly. **How did you fix it?** - I created a `TaskPool` interface; `WorkerPool` implements it (using workers, same implementation as before), but so does `AsyncPool` (a new implementation that simply forwards the call to the `pLimit` limiter). - I feel like this also addresses @merceyz's comment regarding the setting name - it's now called `taskPoolConcurrency`, which doesn't directly refers to workers. - A `getConfigurationWorker` function returns the proper task pool for the given configuration object. To make that possible, WeakMap instances can now be used as storage argument for the `get*WithDefault` family of functions. **Checklist** <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed. --------- Co-authored-by: Anurag Kalia <[email protected]>
- Loading branch information
1 parent
ade06c5
commit fdfc784
Showing
16 changed files
with
214 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
releases: | ||
"@yarnpkg/cli": minor | ||
"@yarnpkg/core": minor | ||
"@yarnpkg/plugin-file": minor | ||
"@yarnpkg/plugin-git": minor | ||
"@yarnpkg/plugin-github": minor | ||
"@yarnpkg/plugin-http": minor | ||
"@yarnpkg/plugin-npm": minor | ||
|
||
declined: | ||
- "@yarnpkg/plugin-compat" | ||
- "@yarnpkg/plugin-constraints" | ||
- "@yarnpkg/plugin-dlx" | ||
- "@yarnpkg/plugin-essentials" | ||
- "@yarnpkg/plugin-exec" | ||
- "@yarnpkg/plugin-init" | ||
- "@yarnpkg/plugin-interactive-tools" | ||
- "@yarnpkg/plugin-link" | ||
- "@yarnpkg/plugin-nm" | ||
- "@yarnpkg/plugin-npm-cli" | ||
- "@yarnpkg/plugin-pack" | ||
- "@yarnpkg/plugin-patch" | ||
- "@yarnpkg/plugin-pnp" | ||
- "@yarnpkg/plugin-pnpm" | ||
- "@yarnpkg/plugin-stage" | ||
- "@yarnpkg/plugin-typescript" | ||
- "@yarnpkg/plugin-version" | ||
- "@yarnpkg/plugin-workspace-tools" | ||
- "@yarnpkg/builder" | ||
- "@yarnpkg/doctor" | ||
- "@yarnpkg/extensions" | ||
- "@yarnpkg/nm" | ||
- "@yarnpkg/pnpify" | ||
- "@yarnpkg/sdks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 25 additions & 7 deletions
32
packages/yarnpkg-core/sources/WorkerPool.ts → packages/yarnpkg-core/sources/TaskPool.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,11 @@ | ||
import {PortablePath, statUtils} from '@yarnpkg/fslib'; | ||
import {ZipFS} from '@yarnpkg/libzip'; | ||
import {parentPort} from 'worker_threads'; | ||
import {parentPort} from 'worker_threads'; | ||
|
||
import {extractArchiveTo, ExtractBufferOptions} from '../tgzUtils'; | ||
import {convertToZipWorker, ConvertToZipPayload} from '../tgzUtils'; | ||
|
||
export type ConvertToZipPayload = {tmpFile: PortablePath, tgz: Buffer | Uint8Array, opts: ExtractBufferOptions}; | ||
|
||
if (!parentPort) | ||
throw new Error(`Assertion failed: Expected parentPort to be set`); | ||
|
||
parentPort.on(`message`, async (data: ConvertToZipPayload) => { | ||
const {opts, tgz, tmpFile} = data; | ||
const {compressionLevel, ...bufferOpts} = opts; | ||
|
||
const zipFs = new ZipFS(tmpFile, {create: true, level: compressionLevel, stats: statUtils.makeDefaultStats()}); | ||
|
||
// Buffers sent through Node are turned into regular Uint8Arrays | ||
const tgzBuffer = Buffer.from(tgz.buffer, tgz.byteOffset, tgz.byteLength); | ||
await extractArchiveTo(tgzBuffer, zipFs, bufferOpts); | ||
|
||
zipFs.saveAndClose(); | ||
|
||
parentPort!.postMessage(data.tmpFile); | ||
parentPort!.postMessage(await convertToZipWorker(data)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export function getContent(): string; | ||
export type {ConvertToZipPayload} from './Worker'; |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.