简体   繁体   English

如何改变Akka路由器的大小?

[英]How to change Akka router size?

I have an Akka router like this: 我有一个像这样的Akka路由器:

ActorRef router = getContext().actorOf(
    new RoundRobinPool(instancecount)
        .props(Props.create(Node.class, po)), po.getUID());

then I want to change the router instancecount . 然后我想更改路由器instancecount What should I do? 我该怎么办?

I think a Resizer could be something you could try to give you elasticity in your router pools to handle bursts of load. 我认为Resizer可能是你可以尝试在路由器池中提供弹性来处理突发负载的东西。 If you wanted to programmatically setup a router with a resizer, then that would look something like this (taken from Akka example on Routing docs): 如果你想以编程方式设置一个带有缩放器的路由器,那么看起来就像这样(取自路由文档中的Akka示例):

val resizer = DefaultResizer(lowerBound = 2, upperBound = 15)
val router3 = system.actorOf(Props[ExampleActor1].withRouter(
  RoundRobinRouter(resizer = Some(resizer))))

In this example, the pool will start out with 2 routees, but can scale up to 15 based on the volume of messages passing through the head of the router pool. 在此示例中,池将以2个路由开始,但可以根据通过路由器池头部的消息量扩展到15个。 You could also do this straight from your akka config. 您也可以直接从您的akka​​配置中执行此操作。 If you had config like this (again from Akka docs): 如果您有这样的配置(再次来自Akka docs):

akka.actor.deployment {
  /myrouter2 {
    router = round-robin
    resizer {
      lower-bound = 2
      upper-bound = 15
    }
  }
}

Then you could setup your pool like this to take advantage of the config: 然后你可以这样设置你的池来利用配置:

val router = system.actorOf(Props[ExampleActor].withRouter(FromConfig()), "myrouter2")

Check out the docs that I linked to for more info on how to setup a Resizer for your pools. 查看我链接的文档,了解有关如何为池设置Resizer更多信息。 Hopefully this is a solution that meets your needs. 希望这是一个满足您需求的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM