python / python/cpython

Include _run_once duration in asyncio debug

オープン
#101,946 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib topic-asyncio type-feature
主要言語
Python
スター
77.2k
フォーク
36k
PR マージ指標
PR 指標を取得中

説明

Feature or enhancement

In asyncio debug mode, log the duration of the asyncio iteration if it exceeds the slow_callback_duration (or a separate duration), as is done now for individual coroutine durations.

Pitch

This will capture when one eventloop iteration is slow, not just because one coroutine is blocking for a while, but because there might be several smaller tasks to process (e.g. 10 10ms operations in one tick blocks incoming operations just as much as one 100ms task, but nothing is logged, currently). It might be less actionable info if it doesn’t log the tasks, but it’s proved useful to us in the past as a more general diagnostic with other event loops (pre-asyncio tornado.IOLoop.set_blocking_log_threshold). This may be an indicator that a web worker is overloaded and more replicas are needed, for example, even if each individual task is handled quickly.

I see three possible versions of this:

  1. like slow coroutines, log only a single time for _run_once if it exceeds a threshold. This doesn't contain actionable info on its own other than 'things are slow'
  2. add to 1. some summary information about the tasks (e.g. log total number and top N coroutines and durations if the sum of durations exceeds some threshold)
  3. replicate tornado's pre-asyncio set_blocking_log_threshold, which logs the stack when the time is crossed via signal.setitimer. The nice thing about this is it can diagnose hangs, not just slowness, unlike after-complete timer logs. Only available where setitimer is also available, of course.

Previous discussion

Brought up originally on async-sig.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Lib/asyncio/base_events.py の、issue で参照されている既存の遅いコールバックの実行時間ロギング付近から始め、次に _run_once がどのように処理されているかを確認します。issue では 3 つの設計案が示されているため、まずどの動作を実装するべきか、またどのしきい値と診断出力が期待されるかを明確にします。完了条件は、対応するカバレッジを備えた、デバッグモードでのイベントループ実行時間診断について合意されていることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。