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