Skip to content

Commit

Permalink
feat: use availableParallelism get the amount of paralllelism avail…
Browse files Browse the repository at this point in the history
…able (#7304)
  • Loading branch information
btea authored Nov 14, 2023
1 parent e2a0c72 commit 1e7bd4a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/breezy-dragons-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/package-requester": patch
"@pnpm/worker": patch
---

Use availableParallelism, when available.
3 changes: 2 additions & 1 deletion pkg-manager/package-requester/src/packageRequester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export function createPackageRequester (
// A lower bound of 16 is enforced to prevent performance degradation,
// especially in CI environments. Tests with a threshold lower than 16
// have shown consistent underperformance.
const networkConcurrency = opts.networkConcurrency ?? Math.max(os.cpus().length, 16)
// @ts-expect-error - `availableParallelism` is not exist until update @types/node to v18.14.5
const networkConcurrency = opts.networkConcurrency ?? Math.max(os.availableParallelism?.() ?? os.cpus().length, 16)

This comment has been minimized.

Copy link
@btea

btea Nov 14, 2023

Author Contributor

I made a mistake here, it should be v18.14.6. @zkochan

const requestsQueue = new PQueue({
concurrency: networkConcurrency,
})
Expand Down
3 changes: 2 additions & 1 deletion worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export async function finishWorkers () {
}

function createTarballWorkerPool (): WorkerPool {
const maxWorkers = Math.max(2, os.cpus().length - Math.abs(process.env.PNPM_WORKERS ? parseInt(process.env.PNPM_WORKERS) : 0)) - 1
// @ts-expect-error - `availableParallelism` is not exist until update @types/node to v18.14.5
const maxWorkers = Math.max(2, (os.availableParallelism?.() ?? os.cpus().length) - Math.abs(process.env.PNPM_WORKERS ? parseInt(process.env.PNPM_WORKERS) : 0)) - 1
const workerPool = new WorkerPool({
id: 'pnpm',
maxWorkers,
Expand Down

0 comments on commit 1e7bd4a

Please sign in to comment.