perf: default network-concurrency to cpu count (#7285)

* feat: default network-concurrency to cpu count

It was found that setting network-concurrency to the exact number of
CPU cores gives fastest installation

* perf: set 16 as min default concurrency

* docs: add comment

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Khải
2023-11-11 02:47:03 +07:00
committed by GitHub
parent 3f7e65e100
commit 4da7b463f6
3 changed files with 12 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---
(Important) Increased the default amount of allowed concurrent network request on systems that have more than 16 CPUs [#7285](https://github.com/pnpm/pnpm/pull/7285).

View File

@@ -237,6 +237,7 @@
"testcase",
"todomvc",
"tsparticles",
"underperformance",
"undollar",
"uninstallation",
"unnest",

View File

@@ -1,4 +1,5 @@
import { createReadStream, promises as fs } from 'fs'
import os from 'os'
import path from 'path'
import {
type FileType,
@@ -97,7 +98,10 @@ export function createPackageRequester (
} {
opts = opts || {}
const networkConcurrency = opts.networkConcurrency ?? 16
// 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)
const requestsQueue = new PQueue({
concurrency: networkConcurrency,
})