2017-03-06 113 views
2
  1. 羣集感知路由器:akka集羣感知路由器和akka集羣分片的不同用例?

    val router = system.actorOf(ClusterRouterPool(
        RoundRobinPool(0), 
        ClusterRouterPoolSettings(
        totalInstances = 20, 
        maxInstancesPerNode = 1, 
        allowLocalRoutees = false, 
        useRole = None 
    ) 
    ).props(Props[Worker]), name = "router") 
    

    在這裏,我們可以將消息發送到router,該郵件將發送到系列遙控routee演員。

  2. 集羣分片(不考慮持久性)

    class NewShoppers extends Actor { 
        ClusterSharding(context.system).start(
        "shardshoppers", 
        Props(new Shopper), 
        ClusterShardingSettings(context.system), 
        Shopper.extractEntityId, 
        Shopper.extractShardId 
    ) 
    
        def proxy = { 
        ClusterSharding(context.system).shardRegion("shardshoppers") 
        } 
    
        override def receive: Receive = { 
        case msg => proxy forward msg 
        } 
    } 
    

    在這裏,我們可以將消息發送到proxy,該郵件將發送到一系列的分片演員(又名實體)的。

所以,我的問題是:it seems both 2 methods can make the tasks distribute to a lot of actors. What's the design choice of above two? Which situation need which choice?

回答

3

池路由器是當你只是想發送一些工作,任何節點,並且有一定的處理,按順序發送兩條消息將可能不會落得在同一個演員進行處理。

集羣分片適用於每個某種類型的actor上都有一個唯一的id,並且您有太多適合一個節點的ID,但是您希望每個帶有該id的郵件總是以actor結尾那個ID。例如,將User建模爲一個實體,您希望關於該用戶的所有命令都以用戶結束,但如果集羣拓撲更改(刪除或添加節點)並且希望它們在現有設備之間進行合理均衡節點。

+0

那麼,一致的哈希池路由器呢?與Cluster分片有什麼不同? – lagom

+0

只要拓撲結構相同,只要它發生變化,它就會將工作發送到同一節點,因爲散列在整個節點集上,所以它可能開始發送到另一個節點。它不會以任何方式通知路由,所以你仍然不能通過這種方式通過id向演員發表演講。 – johanandren

+2

本文:[在Akka.Cluster應用程序中分佈狀態](https://petabridge.com/blog/akkacluster-state-distribution/?utm_source=tuicool&utm_medium=referral)以及johanandren的回答我的問題。 – lagom