elastic / elastic/apm-agent-python

Use single thread with event loop instead of multiple threads

Abierto
#1,812 0 comentarios 1 reacción 1 asignado Reclamado por @beniwohli Ver en GitHub
agent-python feature
Lenguaje dominante
Python
Estrellas
431
Forks
239
Merge medio
5 d 10 h
PR fusionados (30 d)
7

Descripción

**Is your feature request related to a problem? Please describe.**
Currently, the agent creates a bunch of threads on initialization, to do background work:

* a transport thread for sending data to APM Server
* a config thread to periodically fetch central config
* a metrics thread to periodically collect metrics

This is somewhat wasteful, and it's not a great look when users notice that using our agent increases the thread count of their app substantially.

**Describe the solution you'd like**
I think it should be doable to only have one background thread, which runs an asyncio event loop. All tasks that need to run in the background can then be scheduled on that event loop.

One fairly large road block is that urllib3 does not have support for asyncio, and probably won't anytime soon. We would have to switch to another HTTP client library, aiohttp or httpx come to mind. On the plus side, this change might make it easier to finally implement streaming HTTP requests to APM Server and bring us to parity with other backend agents in this respect.

This architecture might even allow us to move other things into the background thread, like reading source files for stack traces.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.