Skip to content
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
7 changes: 7 additions & 0 deletions .changeset/small-results-hunt.md
Original file line number Diff line number Diff line change
@@ -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).
8 changes: 2 additions & 6 deletions pkg-manager/package-requester/src/packageRequester.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createReadStream, promises as fs } from 'fs'
import os from 'os'
import path from 'path'
import {
getFilePathByModeInCafs as _getFilePathByModeInCafs,
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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,
})
Expand Down
2 changes: 1 addition & 1 deletion worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down