python / python/cpython

Include _run_once duration in asyncio debug

未關閉
#101,946 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib topic-asyncio type-feature
主要語言
Python
星號
77.2k
分支
36k
平均合併
1 天 9 小時
30 天內合併 PR
558

描述

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. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Lib/asyncio/base_events.py 中 issue 所引用的現有慢速回呼持續時間記錄附近開始,然後檢視 _run_once 的處理方式。該 issue 提出了三種可能的設計,因此首先釐清應實作哪種行為,以及預期的閾值和診斷輸出。完成的標準是:就 debug-mode 下的事件迴圈持續時間診斷達成共識,並具備相應的覆蓋率。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
backend
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。