python / python/cpython

Include _run_once duration in asyncio debug

Aberta
#101,946 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

stdlib topic-asyncio type-feature
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Merge médio
1d 9h
PRs com merge (30d)
558

Descrição

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.

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece em Lib/asyncio/base_events.py, na área do registro existente da duração de callbacks lentos referenciado na issue, e depois revise como _run_once é tratado. A issue apresenta três designs possíveis, portanto esclareça primeiro qual comportamento deve ser implementado e qual limiar e saída de diagnóstico são esperados. Considera-se concluído quando houver um diagnóstico acordado da duração do event loop no modo de depuração, com a cobertura correspondente.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
backend
Tipo de issue
Funcionalidade
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Estagnada
Clareza
Precisa de esclarecimento
Facilidade para iniciantes
25/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.