You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 30, 2025. It is now read-only.
phobos uses Thread.current[NAMESPACE] thread to save a reference to async_producer
Therefore, it causes threads(memory) leaks in a multithreaded environments (Sidekiq, puma).
the asynchronous producer should be safe to use in a multi-threaded environment. This is because producers, when instantiated, get their own copy of any non-thread-safe data such as network sockets. Furthermore, the asynchronous producer has been designed in such a way to only a single background thread operates on this data while any foreground thread with a reference to the producer object can only send messages to that background thread over a safe queue. Therefore it is safe to share an async producer object between many threads.
This fixes the leak, reduces memory usage and potentially improves performance as messages might be sent in batches.
Problem
phobosusesThread.current[NAMESPACE]thread to save a reference toasync_producerTherefore, it causes threads(memory) leaks in a multithreaded environments (Sidekiq, puma).
code to reproduce
Suggestion
As
ruby-kafkais multithread safe it makes sense to have one instance of async producer per process.https://github.com/zendesk/ruby-kafka?tab=readme-ov-file#thread-safety
This fixes the leak, reduces memory usage and potentially improves performance as messages might be sent in batches.
this can be achieved by updating
create_async_producerandasync_producermethods https://github.com/phobos/phobos/blob/master/lib/phobos/producer.rb#L141as