Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use single thread with event loop instead of multiple threads #1812

Open
beniwohli opened this issue Apr 26, 2023 · 0 comments
Open

Use single thread with event loop instead of multiple threads #1812

beniwohli opened this issue Apr 26, 2023 · 0 comments
Assignees
Milestone

Comments

@beniwohli
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
APM-Agents (OLD)
  
Planned
Development

No branches or pull requests

2 participants