[翻译]squbs官网之12 阻塞式调度器

用于阻塞式API调用的阻塞式调度器

本主题不是关于一般的调度器,而是关于squbs特定的调度器配置。请查看Akka 文档中关于调度器的详细信息。

squbs增加了另外一个预定义的调度器用于阻塞式调用时使用。通常,这用于对数据库的异步调用。reference.conf 定义了blocking-dispatcher ,如下所示:

blocking-dispatcher {
  # Dispatcher is the name of the event-based dispatcher
  type = Dispatcher
  # What kind of ExecutionService to use
  executor = "thread-pool-executor"
  thread-pool-executor {
    # Min number of threads to cap factor-based core number to
    core-pool-size-min = 2
    # The core pool size factor is used to determine thread pool core size
    # using the following formula: ceil(available processors * factor).
    # Resulting size is then bounded by the core-pool-size-min and
    # core-pool-size-max values.
    core-pool-size-factor = 3.0
    # Max number of threads to cap factor-based number to
    core-pool-size-max = 24
    # Minimum number of threads to cap factor-based max number to
    # (if using a bounded task queue)
    max-pool-size-min = 2
    # Max no of threads (if using a bounded task queue) is determined by
    # calculating: ceil(available processors * factor)
    max-pool-size-factor  = 3.0
    # Max number of threads to cap factor-based max number to
    # (if using a  bounded task queue)
    max-pool-size-max = 24
  }
  # 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 = 2
}

对于要使用阻塞式调度器的actor,仅在actor配置中指定,如下所示:

"/mycube/myactor" {
    dispatcher = blocking-dispatcher
  }

如果没有使用阻塞式调度器的任何actor, 则不会初始化阻塞式调度器, 也不需要任何资源。

警告: 阻塞式调度器只能应用于阻塞式调用, 否则性能可能受到严重影响。

你可能感兴趣的:([翻译]squbs官网之12 阻塞式调度器)