nodejs / nodejs/node

os.cpus().length performance on modern AMD CPUs inside containers

Offen
#61,998 6 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.3k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
283

Beschreibung

Version

v24.14.0

Platform
- Bare metal machine
- Host: Linux Ubuntu 24
- Container Image: `node:alpine-24`
- CPU: `AMD EPYC 4584PX 16-Core Processor`
Subsystem

os

What steps will reproduce the bug?

Firstly, I'm not entirely sure if this is a bug, so apologies if this is known or in the wrong spot - it just feels like something that shouldn't be this slow vs other platforms. I couldn't find any other real references to this other than a discussion at https://github.com/nodejs/performance/issues/93 which mentions this being slow.

With a modern AMD CPU such as the one listed above, run the following with Docker:

  • docker run --rm node:24-alpine node -e "console.time('cpus'); os.cpus().length; console.timeEnd('cpus')"

I've also attached an strace output for reference. It seems to iterate over /sys/devices/system/cpu/cpuN/cpufreq/scaling_cur_freq, some of which can take 20ms to return.

strace.log

How often does it reproduce? Is there a required condition?

This requires a modern AMD CPU, with Linux, and run within a container. Otherwise it seems to happen almost 100% of the time in our testing.

What is the expected behavior? Why is that the expected behavior?

I would expect it to return much more quickly as it does on Intel systems.

What do you see instead?

cpus: 649.982ms
regularly >500ms runtime on a machine with 32 cores.

Additional information

No response

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, den Docker-Befehl aus dem Issue auf dem aufgeführten AMD/Linux-Setup zu reproduzieren, und überprüfe das angehängte strace.log. Verfolge den os.cpus()-Pfad, der scaling_cur_freq liest, und vergleiche anschließend das Verhalten mit Intel-Systemen; erledigt ist die Aufgabe, wenn der gemessene Aufruf wesentlich schneller ist, ohne sein Ergebnis zu verändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
docker, javascript, linux, node.js
Bereich
operating-systems, performance
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.