另一種策略可以使用BalancingDispatcher和RoundRobinRouter(作爲一個演員「池」 )。從阿卡文檔:
BalancingDispatcher
# This is an executor based event driven dispatcher that will try to redistribute work from busy actors to idle actors.
# All the actors share a single Mailbox that they get their messages from.
It is assumed that all actors using the same instance of this dispatcher can process all messages that have been sent to one of the actors; i.e. the actors belong to a pool of actors, and to the client there is no guarantee about which actor instance actually processes a given message.
# Sharability: Actors of the same type only
# Mailboxes: Any, creates one for all Actors
# Use cases: Work-sharing
定義您的調度員application.conf或編程方式加載它在啓動時。
private final static Config akkaConfig = ConfigFactory.parseString(
"my-dispatcher.type = BalancingDispatcher \n" +
"my-dispatcher.executor = fork-join-executor \n" +
"my-dispatcher.fork-join-executor.parallelism-min = 8 \n" +
"my-dispatcher.fork-join-executor.parallelism-factor = 3.0 \n" +
"my-dispatcher.fork-join-executor.parallelism-max = 64 "
);
然後爲路由定義路由器和調度器。
getContext().actorOf(new Props(MyActor.class).withRouter(new RoundRobinRouter(10)).withDispatcher("my-dispatcher"), "myActor");
那麼路由器將簡單地去「分配」的消息,並分發器將運行選定的演員(和它實現工作竊取以及)
我經歷了Akka的路由,這就是爲什麼我決定不使用路由器(也許我應該寫我自己的),因爲我無法查詢路由器關於工人的閒置狀態(也許我錯了,你能指出我在哪裏看看?) – DodoTheDeadDoo 2012-07-07 20:17:19
不是故意按下輸入...無論如何,我會研究毒丸解決方案,就像我現在正在做的一樣,我不殺死一個工人,我只是將它設置爲空閒狀態,以便它可以被重新利用......當我沒有更多的任務時而且所有的工人都比我知道我已經完成了。 – DodoTheDeadDoo 2012-07-07 20:21:24
所以我會寫我自己的路由器:) – DodoTheDeadDoo 2012-07-11 14:24:00