elastic / elastic/apm-agent-python

Use single thread with event loop instead of multiple threads

Aperta
#1,812 0 commenti 1 reazione 1 assegnatario Rivendicata da @beniwohli Vedi su GitHub
agent-python feature
Lingua principale
Python
Stelle
431
Fork
239
Merge medio
5g 10h
PR unite (30g)
7

Descrizione

**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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.