gpt4 book ai didi

java - 了解 akka 中的调度程序

转载 作者:行者123 更新时间:2023-11-30 06:52:13 27 4
gpt4 key购买 nike

我在 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. 这是否意味着每个 actor 系统唯一实例表示任何已配置的调度程序?

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

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

最佳答案

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

回答具体问题:

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

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

关于java - 了解 akka 中的调度程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39396238/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com