如何限制特定类型的参与者的数量? [英] How to limit the number of actors of a particular type?
问题描述
我已经创建了一个演员,可以将消息发送到聊天服务器。但是,聊天服务器仅允许每个用户5个连接。如果我锤打我的Scala服务器,我会收到错误消息,因为我的聊天客户端断开了连接。
I've created an actor to send messages to a chat server. However, the chat server only permits 5 connections per user. If I hammer my scala server I get error messages because my chat clients get disconnected.
所以我该如何配置akka,以便我的 XmppSenderActor
s最多只能使用5个线程?我不想限制角色系统的其余部分,而只限制该对象(在路径 / XmppSenderActor /
处)。
So how can I configure akka so that my XmppSenderActor
s only use a maximum of 5 threads? I don't want to restrict the rest of the actor system, only this object (at the path /XmppSenderActor/
).
我正在尝试此配置,因为我认为这是我需要配置的调度程序,但是我不确定:
I'm trying this config since I think it's the dispatcher I need to configure, but I'm not sure:
akka.actor.deployment {
/XmppSenderActor {
dispatcher = xmpp-dispatcher
}
xmpp-dispatcher {
fork-join-executor.parallelism-min = 2
fork-join-executor.parallelism-max = 3
}
}
这给我一个错误: akka.ConfigurationException:未为路径akka:// sangria-server / user / XmppSenderActor配置Dispatcher [xmpp-dispatcher]
推荐答案
我可能会尝试配置路由器。
I would probably try to configure a Router instead.
http://doc.akka.io/docs/ akka / 2.0 / scala / routing.html
调度员似乎在处理s
该配置特别适合您:
akka.actor.deployment {
/router {
router = round-robin
nr-of-instances = 5
}
}
nr-of-instances
将从一开始就创建5个孩子,因此可以满足您的需求。
不过,您可能需要找到正确的路由器实现。
The nr-of-instances
will create 5 childrens from the get going and therefore fill your needs.
You might need to find the right Router implementation though.
这篇关于如何限制特定类型的参与者的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!