简体   繁体   English

了解Akka中的调度员

[英]Understanding dispatchers in akka

I read the documentation about dispatchers on the official site . 在官方网站上阅读了有关调度员的文档。 but it's still not clear about what dispatcher is the beast. 但尚不清楚哪个调度员是野兽。 For example, it may be configured as follows: 例如,可以将其配置如下:

my-thread-pool-dispatcher {
  # Dispatcher is the name of the event-based dispatcher
  type = Dispatcher
  # What kind of ExecutionService to use
  executor = "thread-pool-executor"
  # Configuration for the thread pool
  thread-pool-executor {
    # minimum number of threads to cap factor-based core number to
    core-pool-size-min = 2
    # No of core threads ... ceil(available processors * factor)
    core-pool-size-factor = 2.0
    # maximum number of threads to cap factor-based number to
    core-pool-size-max = 10
  }
  # Throughput defines the maximum number of messages to be
  # processed per actor before the thread jumps to the next actor.
  # Set to 1 for as fair as possible.
  throughput = 100
}

QUESTIONS: 问题:

  1. Does it mean that any configured dispatcher represented by the only one instance per actor system? 这是否意味着每个actor系统一个实例表示的任何已配置的调度程序?

  2. Can one instance of a dispatcher manage more than one executors (thread pool, fork-join pool)? 调度程序的一个实例可以管理多个执行程序(线程池,派生联接池)吗?

  3. If there's only one instance of each configured dispatcher, how do different actors (perhaps on different nodes) interact with it? 如果每个已配置的调度程序只有一个实例,那么不同的参与者(也许在不同的节点上)如何与之交互?

Easiest is to think about a dispatcher as about a thread pool (which it really is) that is used to run your actors. 最简单的方法是将调度程序视为用于运行角色的线程池(实际上是线程池)。 Depending on the nature of your actors you can run them on fork-join thread pool (most common) or on CachedThreadPool (if you're dong IO) etc. I highly recommend this article that explains thread pools very nicely. 根据角色的性质,您可以在fork-join线程池(最常见)或CachedThreadPool(如果您是IO专家)等上运行它们。我强烈建议您这篇文章,它很好地解释了线程池。

To answer the specific questions: 要回答具体问题:

  1. Yes, you have one Dispatcher instance per configuration entry. 是的,每个配置条目都有一个Dispatcher实例。 You can have as many configurations as you want though (although it's likely not practical to have more than a few Dispatchers). 您可以根据需要拥有任意数量的配置(尽管拥有多个分派器可能不切实际)。 Effectively config you described above creates you a named Dispatcher instance. 上面描述的有效配置可以创建一个命名的Dispatcher实例。
  2. Dispatcher is a sort of wrapper around Executor (as I understand it) to facilitate communication with actor API. Dispatcher是Executor的一种包装(据我所知),以促进与actor API的通信。 So no, one dispatcher means one executor. 因此,不,一位调度员意味着一位执行者。
  3. There is a default system dispatcher that is used by actors when other dispatcher is not explicitly specified. 没有明确指定其他调度程序时,参与者将使用默认的系统调度程序。 Documentation you referred explains how to run actors on non-default dispatchers, either though API or through configuration. 您引用的文档说明了如何通过API或通过配置在非默认调度程序上运行actor。 I don't quite understand "different nodes" part of the question. 我不太了解问题的“不同节点”部分。 Dispatchers are concepts within JVM. 调度程序是JVM中的概念。 When actors communicate across nodes dispatcher being used is not relevant. 当参与者在节点之间进行通信时,所使用的调度程序并不重要。 If that does not answer your question, please clarify. 如果这样不能回答您的问题,请澄清。

You can create multiple Dispatchers of the same kind using the config above. 您可以使用上面的配置创建多个相同种类的分派器。

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

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