feat: use availableParallelism get the amount of paralllelism available (#7304)

This commit is contained in:
btea
2023-11-14 17:57:28 +08:00
committed by GitHub
parent e2a0c72720
commit 1e7bd4af3a
3 changed files with 10 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/package-requester": patch
"@pnpm/worker": patch
---
Use availableParallelism, when available.

View File

@@ -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)
const requestsQueue = new PQueue({
concurrency: networkConcurrency,
})

View File

@@ -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,