Windows bench_command memory tracking fails
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 20/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- python
- 領域
- performance
調査の方向性
まず Windows コマンドのベンチマークを再現し、pyperf/_process_time.py、_win_memory.py、_runner.py、_worker.py の参照されているセクションを読んでください。各プラットフォームがメモリ追跡をどのように選択するか、また既存のコードがどの測定値を想定しているかを比較してください。合意されたメモリ指標が選択され、コマンドのベンチマークが Windows で正常に実行され、関連する動作がテストでカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Creating a new issue to track a PR I'm working on to fix the issue in the title. Related issue from May 2021: #97
I was attempting to track the memory usage of command benchmarks on Windows, but got the following errors when doing so:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "D:\my_project\.venv\Lib\site-packages\pyperf\__main__.py", line 769, in <module>
main()
File "D:\my_project\.venv\Lib\site-packages\pyperf\__main__.py", line 765, in main
func()
File "D:\my_project\.venv\Lib\site-packages\pyperf\__main__.py", line 734, in cmd_bench_command
runner.bench_command(name, command)
File "D:\my_project\.venv\Lib\site-packages\pyperf\_runner.py", line 747, in bench_command
return self._main(task)
^^^^^^^^^^^^^^^^
File "D:\my_project\.venv\Lib\site-packages\pyperf\_runner.py", line 460, in _main
bench = self._worker(task)
^^^^^^^^^^^^^^^^^^
File "D:\my_project\.venv\Lib\site-packages\pyperf\_runner.py", line 434, in _worker
run = task.create_run()
^^^^^^^^^^^^^^^^^
File "D:\my_project\.venv\Lib\site-packages\pyperf\_worker.py", line 299, in create_run
self.compute()
File "D:\my_project\.venv\Lib\site-packages\pyperf\_command.py", line 70, in compute
raise RuntimeError("failed to get the process RSS")
RuntimeError: failed to get the process RSS
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "\.venv\Scripts\pyperf.exe\__main__.py", line 10, in <module>
File "D:\my_project\.venv\Lib\site-packages\pyperf\__main__.py", line 765, in main
func()
File "D:\my_project\.venv\Lib\site-packages\pyperf\__main__.py", line 734, in cmd_bench_command
runner.bench_command(name, command)
File "D:\my_project\.venv\Lib\site-packages\pyperf\_runner.py", line 747, in bench_command
return self._main(task)
^^^^^^^^^^^^^^^^
File "D:\my_project\.venv\Lib\site-packages\pyperf\_runner.py", line 465, in _main
bench = self._manager()
^^^^^^^^^^^^^^^
File "D:\my_project\.venv\Lib\site-packages\pyperf\_runner.py", line 678, in _manager
bench = Manager(self).create_bench()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\my_project\.venv\Lib\site-packages\pyperf\_manager.py", line 243, in create_bench
worker_bench, run = self.create_worker_bench()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\my_project\.venv\Lib\site-packages\pyperf\_manager.py", line 142, in create_worker_bench
suite = self.create_suite()
^^^^^^^^^^^^^^^^^^^
File "D:\my_project\.venv\Lib\site-packages\pyperf\_manager.py", line 132, in create_suite
suite = self.spawn_worker(self.calibrate_loops, 0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\my_project\.venv\Lib\site-packages\pyperf\_manager.py", line 118, in spawn_worker
raise RuntimeError("%s failed with exit code %s"
RuntimeError: D:\my_project\.venv\Scripts\python.exe failed with exit code 1
I debugged my way through the code and ended up getting the root cause, which is located here: https://github.com/psf/pyperf/blob/e0610c2f263c300de870e7bc8e494d46e0fd71be/pyperf/_process_time.py#L25-L42
In short, this function gets the current process resident set size by using the resource library, but this library is only available on Linux. When run on Windows, this function simply returns 0, which causes the downstream callers to see this as an error and fail running the benchmark entirely.
I began working on a fork where I instead use psutil to get the current process' RSS, but I noticed that psutil.Process().memory_info().rss returns higher values than the measurements from the resource library. I'm seeing roughly 25% - 35% higher RSS size with psutil`, so that leads to a dilemma in terms of accuracy across operating systems. We have a few options:
psutilworks cross-platform, but therssvalues are not accurate with what theresourcemodule gets. We can opt to only usepsutilmoving forward, but that would invalidate all existing command benchmark results until they are re-run.- We can use
psutilonly for Windows systems, but this leads to a memory usage discrepancy between operating systems. On my Mac Mini, theresourceandpsutilRSS sizes did not match by a wide margin, so for Windows systems it would falsely appear to have higher memory usage than Mac systems (and presumably Linux ones as well). - We can use some other data point, such as the Unique Set Size from
psutilthroughpsutil.Process().memory_full_info().uss. USS is closer to what theresourcemodule gets for RSS, but now USS is about 15% smaller than RSS from theresourcemodule. USS is supposed to be the closest representation of the process memory usage, which should be more ideal than RSS or peak RSS
I'm not aware of any other ways to get the memory usage of a process without writing some C bindings to do so. What's more confusing is that there is also the _win_memory.py file that uses Windows-native functionality to track memory usage, but from my testing that's not used correctly - if it was then I wouldn't be getting the above error.
I see in both _runner.py and _worker.py that we break down what method to use based on what OS is running. If we go with using psutil for the unifying the memory tracking of command benchmarks, should we do the same for regular benchmarks?
- 主要言語
- Python
- スター
- 967
- フォーク
- 112
- 平均マージ
- 5日 8時間
- マージ済み PR(30日)
- 9
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
psf/pyperf のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
Improve Type System for `pyperf`対応中かも @DebanKsahu が 69 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 32/100
メンテナーはふだん 1 日以内に返信
-
Extend hook's teardown metadata with warmup/calibration flags対応中かも @maurycy が 170 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
-
2.6.2: sphinx warnings `reference target not found`対応中かも @amritamishra01 が 356 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
add entry to blockオープン
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
StevenBlack/hosts#3299 ·
-
`garak --report` overwrites the input report when its name has no ".report"対応中かも @0z5a が今日担当しました。 オープンneeds-triage
難易度 2/5 半日 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
plot_graph crashes when a mesh node has no m2m edge対応中かも @tygvi が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
mllam/neural-lam#883 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
future-agi/future-agi#4092 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
transcript analytics: a text whose only protected spans the prose pass redacts is withheld wholeオープン
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
WingedGuardian/GENesis-AGI#4641 ·
メンテナーはふだん 1 日以内に返信