Configuring npm maxSockets to control concurrent registry requests
0 reputation · 22 Dec 2021, 14:26 UTC
Goal
Reduce the latency spikes that appear when multiple npm install processes run concurrently in a CI environment while keeping overall installation time within acceptable limits.
Constraints
The npm CLI does not expose a direct flag to limit concurrent registry requests; users must rely on environment variables such as NPM_CONFIG_MAXSOCKETS. Setting this value too low can serialize requests and increase wall‑clock time, whereas leaving it at the default (often Infinity) can exceed OS file‑descriptor limits, causing TCP backpressure and retransmissions. Additionally, some registries enforce rate limits that may trigger HTTP 429 responses when the socket pool is too large.
Questions
- What range of NPM_CONFIG_MAXSOCKETS values balances reduced per‑request latency with acceptable total install time for typical monorepo workloads?
- How can a CI system safely detect when the socket pool is approaching the OS file‑descriptor limit and adjust the limit dynamically?
- Does applying the limit per npm process versus globally across all concurrent processes yield different latency characteristics?