Skip to content

Conversation

joshuay03
Copy link

@joshuay03 joshuay03 commented Aug 27, 2025

Our (@buildkite's) Datadog profiler reported numerous threads being spawned by this gem in one of our services. We tracked it down to this return statement which causes the worker thread to terminate whenever the queue is empty:

ensure_worker_running

This creates unnecessary thread churn in long-running applications. Instead of terminating when the queue is empty, the worker thread should remain alive and wait for new messages. The current behavior causes the thread to die and be replaced repeatedly - each time the queue empties and then receives new messages, a new thread must be spawned, which is inefficient, especially when analytics are emitted frequently.

This PR fixes the issue by replacing the early return with a sleep/continue pattern, keeping the worker thread alive during idle periods.

@joshuay03 joshuay03 moved this to In Progress / Pending Review in Open Source Aug 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant