Open krisleech opened 9 years ago
Not sure this will be possible (or useful) because we have to wrap listeners at runtime in an Actor, this the actor is not reusable, unless it is globally subscribed. But the broadcaster does not know if it is a global subscription.
The problem with the current design is an unlimited number of actors can be spawned. Which could use all resources.
Maybe instead of wrapping the listener at runtime we have a persistant pool of actors which can accept messages which take a subscriber and the event name and simply do listener.public_send(event, *args)
or use SendBroadcaster
...
Actors do not block when mailbox full they either drop the message or raise. This will result in lost messages. A supervisor would capture exception and re-publish (assuming simple event arguments, which they should be anyway).
Celluloid gives us a way to register actors, or pools, globally: Celluloid::Actor[:wisper_listener_pool]
From my experiment it looks like pools do block until there is a free actor.
Currently we use a single Actor, so a single thread, it is just backgrounded. If we used a pool of actors we would also be able distribute events across CPU's. Default to a pool size of 10.
Need to ensure that a pool will block when all actors are in use, this allows us to constrain the max CPU/mem useage.