Akka Pool Router

65 views
Skip to first unread message

mladen....@gmail.com

unread,
Mar 14, 2017, 4:26:36 AM3/14/17
to Akka User List
To explain my issue in a clear way I provided a sample code:

if I have an actor which looks like this:

class MasterActor extends Actor with ActorLogging with WorkerRouter with AkkaProvider {
   
 
private val router = createWorkerRouter()


 
def receive = {
     
case PurchaseOrderMsg(content,timestamp) =>
       router
! Response(timestamp)


trait
WorkerRouter {this: Actor =>
 
def createWorkerRouter(): ActorRef = {
    val resizer
= DefaultResizer(lowerBound = 2, upperBound = 15)
    context
.actorOf(
       
ClusterRouterPool(RoundRobinPool(7,Some(resizer)),
                           
ClusterRouterPoolSettings(
                                  totalInstances
= Int.MaxValue,
                                  maxInstancesPerNode
= 10,
                                  allowLocalRoutees
= false,
                                  useRole
= Some("worker"))
                           
).props(Worker.props(???),
                           name
= "purchase-order-router")
     
}
}

How do I pass dynamically props to createWorkerRouter from my MasterActor?
I use the props from the Worker as persistence_id since it's a FSM therefore it has to be unique.

Patrik Nordwall

unread,
Mar 15, 2017, 2:19:07 AM3/15/17
to Akka User List
What persistenceIds would you like to use in the end?

Based on a counter? PO-1, PO-2, ... increasing for each routee?
Would be strange in a long running system when worker nodes are added and removed over time.

Why not use Cluster Sharding instead? Wouldn't it be more natural to have a separate entity actor for each purchase order instead of using round-robin.

/Patrik
--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

mladen....@gmail.com

unread,
Mar 15, 2017, 4:05:51 AM3/15/17
to Akka User List
It is hard to explain, but in short my master actor receives a message which is then forwarded to the respective worker, and from that message I extract business information to make my worker's (FSM) persistenceId unique.

After I second thought, maybe I misunderstood the router concept - I just realized that this code load balances the work between the actors, but you are right, I need to find a way how to distribute it equally among the nodes which I suppose is done by the cluster sharding.
Reply all
Reply to author
Forward
0 new messages