mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
perf: increase the default network concurrency on machines with many CPU cores (#10215)
close #10068
This commit is contained in:
7
.changeset/small-results-hunt.md
Normal file
7
.changeset/small-results-hunt.md
Normal 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).
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user