perf: increase the default network concurrency on machines with many CPU cores (#10215)

close #10068
This commit is contained in:
Zoltan Kochan
2025-11-21 15:29:56 +01:00
committed by GitHub
parent a5fdbf9bb3
commit 4893853569
3 changed files with 10 additions and 7 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/package-requester": minor
"@pnpm/worker": minor
"pnpm": minor
---
Increase the network concurrency on machines with many CPU cores. We pick a network concurrency that is not less than 16 and not more than 64 and it is calculated by the number of pnpm workers multiplied by 3 [#10068](https://github.com/pnpm/pnpm/issues/10068).

View File

@@ -1,5 +1,4 @@
import { createReadStream, promises as fs } from 'fs'
import os from 'os'
import path from 'path'
import {
getFilePathByModeInCafs as _getFilePathByModeInCafs,
@@ -44,7 +43,7 @@ import {
} from '@pnpm/store-controller-types'
import { type DependencyManifest, type SupportedArchitectures } from '@pnpm/types'
import { depPathToFilename } from '@pnpm/dependency-path'
import { readPkgFromCafs as _readPkgFromCafs } from '@pnpm/worker'
import { calcMaxWorkers, readPkgFromCafs as _readPkgFromCafs } from '@pnpm/worker'
import { familySync } from 'detect-libc'
import PQueue from 'p-queue'
import pDefer, { type DeferredPromise } from 'p-defer'
@@ -111,10 +110,7 @@ export function createPackageRequester (
} {
opts = opts || {}
// 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.availableParallelism?.() ?? os.cpus().length, 16)
const networkConcurrency = opts.networkConcurrency ?? Math.min(64, Math.max(calcMaxWorkers() * 3, 16))
const requestsQueue = new PQueue({
concurrency: networkConcurrency,
})

View File

@@ -52,7 +52,7 @@ function createTarballWorkerPool (): WorkerPool {
return workerPool
}
function calcMaxWorkers () {
export function calcMaxWorkers (): number {
if (process.env.PNPM_MAX_WORKERS) {
return parseInt(process.env.PNPM_MAX_WORKERS)
}