Hello dear Hakkers,

I'd be very thankful if you will help me the following question. I hope it 
is okay if I will copy content from my question of StackOverflow here 
http://stackoverflow.com/questions/34828746/akkas-actor-based-custom-event-bus-implementation-casues-bottleneck
 
.

I'm trying to implement Event Bus (Pub-Sub) pattern on top of Akka's actors 
model. 

"Native" EventBus 
<http://doc.akka.io/docs/akka/snapshot/scala/event-bus.html> implementation 
doesn't meet some of my requirements (e.g. possibility of retaining only 
last message in a topic, it's specific for MQTT protocol, I'm implementing 
message broker for it https://github.com/butaji/JetMQ).

Current interface of my EventBus is the following:

object Bus {
  case class Subscribe(topic: String, actor: ActorRef)
  case class Unsubscribe(topic: String, actor: ActorRef)
  case class Publish(topic: String, payload: Any, retain: Boolean = false)}

And usage looks like this:

val system = ActorSystem("System")val bus = system.actorOf(Props[MqttEventBus], 
name = "bus")val device1 = system.actorOf(Props(new DeviceActor(bus)))val 
device2 = system.actorOf(Props(new DeviceActor(bus)))

All the *devices* have the reference to a single Bus actor. Bus actor is 
responsible for storing of all the state of subscriptions and topics (e.g. 
retain messages).

*Device actors* inside themselves can decide whatever they want to Publish, 
Subscribe or Unsubscribe to topics.

After some performance benchmarks, I realized that my current design 
affects processing time between Publishings and Subscriptions for the 
reasons that:

   1. My EventBus actually is a singleton 
   2. It is caused a huge queue of processing load for it

*How can I distribute* (parallelize) workload for my event bus 
implementation? Is the current solution good to fit akka-cluster?

Currently, I'm thinking about routing 
<http://doc.akka.io/docs/akka/snapshot/scala/routing.html> through several 
instances of Bus as the following:

val paths = (1 to 5).map(x => {
  system.actorOf(Props[EventBusActor], name = "event-bus-" + x).path.toString})
val bus_publisher = system.actorOf(RoundRobinGroup(paths).props())val 
bus_manager = system.actorOf(BroadcastGroup(paths).props())

Where:

   - *bus_publisher* will be responsible for getting Publish, 
   - *bus_manager* will be responsible for getting Subscribe / Unsubscribe. 

And as the following it will replicate state across all the buses and 
reduce queue per actor with the distribution of the load.

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to