了解 akka 中的调度员

use*_*882 3 java scala akka

在官方网站上阅读了有关调度员的文档。但目前还不清楚什么调度员是野兽。例如,它可以配置如下:

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
}
Run Code Online (Sandbox Code Playgroud)

问题:

  1. 这是否意味着每个actor系统只有一个实例代表任何已配置的调度程序?

  2. 一个调度程序的一个实例可以管理多个执行程序(线程池、fork-join 池)吗?

  3. 如果每个配置的调度程序只有一个实例,不同的参与者(可能在不同的节点上)如何与其交互?

Tim*_*Tim 5

最简单的方法是将调度程序视为用于运行actor 的线程池(它确实是)。根据您的演员的性质,您可以在 fork-join 线程池(最常见)或 CachedThreadPool(如果您是 dong IO)等上运行它们。我强烈推荐这篇文章,它非常好地解释了线程池。

回答具体问题:

  1. 是的,每个配置条目都有一个 Dispatcher 实例。不过,您可以拥有任意数量的配置(尽管拥有多个 Dispatcher 可能不切实际)。上面描述的有效配置会为您创建一个命名的 Dispatcher 实例。
  2. Dispatcher 是一种围绕 Executor(据我所知)的包装器,以促进与 Actor API 的通信。所以不,一个调度员意味着一个执行者。
  3. 当没有明确指定其他调度程序时,actor 会使用一个默认的系统调度程序。您参考的文档解释了如何通过 API 或通过配置在非默认调度程序上运行 actor。我不太明白问题的“不同节点”部分。调度程序是 JVM 中的概念。当参与者跨节点通信时,正在使用的调度程序不相关。如果这不能回答您的问题,请澄清。

您可以使用上面的配置创建多个相同类型的 Dispatcher。