用于阻塞式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, 則不會初始化阻塞式調度器, 也不需要任何資源。
警告: 阻塞式調度器只能應用于阻塞式調用, 否則性能可能受到嚴重影響。