另一种策略可以使用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