简体   繁体   English

用UUID命名时,为akka actor定义调度程序

[英]defining dispatcher for akka actor when named with UUID

I have a play application built on java using Akka actor. 我有一个使用Akka actor在java上构建的播放应用程序。 Recently I came across performance issues with related to parallelism. 最近,我遇到了与并行性有关的性能问题。 I have gone through Google and found that we can assign custom/pinned dispatchers/executors to actors. 我遍历了Google,发现我们可以为角色分配自定义/固定的调度程序/执行程序。 At the time of actor creation, I have named the actor with actor name appended with unique ID. 在创建actor时,我已经给actor命名了actor名称,并附加了唯一的ID。

Is there a way to specify my actors to use pinned dispatcher when the actor names are appended with unique ID. 当演员名称后附加唯一ID时,是否有一种方法可以指定我的演员使用固定分派器。

I am trying to update the application.conf as below and not getting the result as expected. 我正在尝试按以下方式更新application.conf,但未获得预期的结果。 It is still using default dispatcher. 它仍在使用默认调度程序。

My actors are at akka://application/user/actor 我的演员位于akka:// application / user / actor

akka.actor.deployment {
  "/actorName*" {
       dispatcher =  mycustom-dispatcher
  }
}

References I used: http://doc.akka.io/docs/akka/2.1.4/java/dispatchers.html#Setting_the_dispatcher_for_an_Actor 我使用的参考资料: http : //doc.akka.io/docs/akka/2.1.4/java/dispatchers.html#Setting_the_dispatcher_for_an_Actor

Yes, you can explicitly assign a dispatcher to your actor[s]. 是的,您可以为您的演员明确分配调度员。

import akka.actor.Props
val myActor =
  context.actorOf(Props[MyActor].withDispatcher("my-dispatcher"), "myactor1")

or java variant: 或Java变体:

ActorRef myActor =
  system.actorOf(Props.create(MyUntypedActor.class).withDispatcher("my-dispatcher"),
    "myactor3");

with configuration 配置

my-dispatcher {
  executor = "thread-pool-executor"
  type = PinnedDispatcher
}

Check for more the akka-docs 查看更多akka-docs

You have to specify which dispatcher to use with your actors, usually you pass an execution context where you can specify which dispatcher to use: 您必须指定与actor一起使用的调度程序,通常您传递一个执行上下文,在其中可以指定要使用的调度程序:

implicit val executionContext = system.dispatchers.lookup("my-dispatcher")

You can also change the default dispatcher like specified here: https://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html#default-dispatcher 您还可以像在此指定的那样更改默认调度程序: https : //doc.akka.io/docs/akka/snapshot/scala/dispatchers.html#default-dispatcher

akka.actor.deployment {
  "/actorName*" {
    dispatcher =  mycustom-dispatcher
  }
}

The above doesn't work, because (from the documentation ): 上面的方法不起作用,因为(来自文档 ):

  • wildcards cannot be used to partially match section, like this: /foo*/bar , /f*o/bar etc. 通配符不能用于部分匹配部分,例如: /foo*/bar/f*o/bar等。

You can, however, use a wildcard to match all actors at a certain level in the actor hierarchy. 但是,您可以使用通配符来匹配参与者层次结构中特定级别的所有参与者。 For example, let's say that all of the actors for which you want to use the custom dispatcher live under akka://application/user/someParent/ . 例如,假设您要使用自定义调度akka://application/user/someParent/所有参与者都位于akka://application/user/someParent/ You could then configure all of someParent 's direct children in the following way: 然后,您可以通过以下方式配置someParent的所有直接子代:

akka.actor.deployment {
  "/someParent/*" {
    dispatcher =  mycustom-dispatcher
  }
}

Read the linked documentation for more options. 阅读链接的文档以获取更多选项。

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

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