os.cpus().length performance on modern AMD CPUs inside containers
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 283
説明
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.
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、記載されている AMD/Linux セットアップで issue の Docker コマンドを再現し、添付された strace.log を確認します。scaling_cur_freq を読み取る os.cpus() のパスを追跡し、その後 Intel システムとの動作を比較します。測定した呼び出しが結果を変えずに大幅に高速化されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- docker, javascript, linux, node.js
- 領域
- operating-systems, performance
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100