【问题标题】:Understanding dispatchers in akka了解akka中的调度程序
【发布时间】:2016-09-10 12:48:02
【问题描述】:

我在the official site 上阅读了有关调度程序的文档。但目前还不清楚什么调度员是野兽。比如可以这样配置:

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
}

问题:

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

  2. 一个调度程序实例能否管理多个执行器(线程池、fork-join 池)?

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

【问题讨论】:

    标签: java scala akka


    【解决方案1】:

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

    回答具体问题:

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

    您可以使用上面的配置创建多个相同类型的调度程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-04
      • 2015-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-20
      相关资源
      最近更新 更多