krisleech / wisper-celluloid

Provides async event broadcasting to Wisper using Celluloid
MIT License
17 stars 4 forks source link

Allow pool of actors to process events #2

Open krisleech opened 9 years ago

krisleech commented 9 years ago

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.

Wisper::Celluloid.configure do |c|
  c.pool_size = 100
end
krisleech commented 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...

krisleech commented 9 years ago

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

krisleech commented 9 years ago

Celluloid gives us a way to register actors, or pools, globally: Celluloid::Actor[:wisper_listener_pool]

krisleech commented 9 years ago

From my experiment it looks like pools do block until there is a free actor.