You could read up on sharding and see if that is what you're after, I think 
it could be since you are basically describing that you would have one 
worker per id rather
than distributing messages for M ids over N actors:
http://doc.akka.io/docs/akka/2.4.0/scala/cluster-sharding.html


On Tuesday, November 17, 2015 at 3:57:07 PM UTC+1, Danny Lesnik wrote:
>
>
>
> Thank you for the response. it looks much better, but now I see that all 
> my three "statsWorker" actors created on the node initiation.
>
> Is there any option to start "statsWorker" actors dynamically, for example 
> if I'm sending messages with id range between [1..10] i will have 10 
> distributed "statsWorker"  actors if the range of id's increases from to 20 
> and I'm sending messages with id range[1..20], i have 20 distributed actors 
> each actor for each id. 
>
> Is it possible?  
>
> On Tuesday, November 17, 2015 at 11:28:08 AM UTC+2, Danny Lesnik wrote:
>>
>> I'm playing with "stats" example to make some kind of POC: 
>>
>> and have the following configuration:
>>
>> application.conf:
>>
>> akka.actor.deployment {
>>   /singleton/statsService/statsWorker {
>>     router = consistent-hashing-pool
>>     nr-of-instances = 100
>>     cluster {
>>       enabled = on
>>       max-nr-of-instances-per-node = 3
>>       allow-local-routees = on
>>       use-role = backend
>>     }
>>   }
>>
>> }
>>
>> I have 3 nodes one with the role "frontend" and two with the role 
>> "backend":
>>
>>  I'm sending the following message: 
>>
>> case class TestMessage(id:Int,msg:String) extends ConsistentHashable {
>>   override def consistentHashKey: Any = id.toString
>> }
>>
>>
>> now I have StatsService actor:
>>
>>
>> class StatsService extends Actor{
>>
>>   override def preStart(): Unit = println("starting singleton statsService")
>>
>>   val statsWorker = context.actorOf(Props[StatsWorker],"statsWorker")
>>
>>   override def receive ={
>>     case testMsg:TestMessage => statsWorker ! testMsg
>>     case _ => println("unhelded")
>>   }
>> }
>>
>>
>> Now  statsWorker:
>>
>>
>> class StatsWorker extends Actor{
>>
>>   override def preStart(): Unit = println("Start new Stats Worker!!!")
>>
>>   override def receive = {
>>     case TestMessage(id,msg) => println(id)
>>     case _ => println("unhelded")
>>   }
>> }
>>
>>
>> Now on each node I have the following code:
>>
>>
>>    val nodeRole = configuration.getStringList("akka.cluster.roles").get(0)
>>
>>
>>   if (nodeRole == "backend") {
>>
>>     system.actorOf(ClusterSingletonManager.props(
>>     singletonProps = Props[StatsService], singletonName = "statsService",
>>     terminationMessage = PoisonPill, role = Some("backend")),
>>     name = "singleton")
>>
>> } else if (nodeRole=="frontend"){
>>     val statsServiceProxy = 
>> system.actorOf(ClusterSingletonProxy.props(singletonPath = 
>> "user/singleton/statsService", 
>>
>>                                            role = Some("backend")), name = 
>> "statsServiceProxy")
>>
>>     for (a <- 1 to 10000) {
>>       statsServiceProxy ! TestMessage(a, "bla")
>>     }
>>   }
>>
>>
>>
>> *Now I see the following concerns:*
>>
>>
>> 1) My "statsService" singleton created on leader and seems to be single 
>> instance in cluster, which is OK.
>>
>> 2) Only one instance of statsWorker created, but as far as I understand i 
>> supposed to have 3 instances on each node. 
>>
>> 3) All 10k messages are handled by single instance of "statsWorker" which is 
>> not OK.
>>
>> 4) it seems like I'm using simple singleton pattern and it looks like my 
>> pool is not working.
>>
>> What is wrong? How can I balance between two "backend" nodes? 
>>
>>

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

Reply via email to