用于阻塞式API調(diào)用的阻塞式調(diào)度器
本主題不是關(guān)于一般的調(diào)度器泉哈,而是關(guān)于squbs特定的調(diào)度器配置。請查看Akka 文檔中關(guān)于調(diào)度器的詳細(xì)信息破讨。
squbs增加了另外一個預(yù)定義的調(diào)度器用于阻塞式調(diào)用時使用丛晦。通常,這用于對數(shù)據(jù)庫的異步調(diào)用提陶。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
}
對于要使用阻塞式調(diào)度器的actor,僅在actor配置中指定搁骑,如下所示:
"/mycube/myactor" {
dispatcher = blocking-dispatcher
}
如果沒有使用阻塞式調(diào)度器的任何actor, 則不會初始化阻塞式調(diào)度器, 也不需要任何資源斧吐。
警告: 阻塞式調(diào)度器只能應(yīng)用于阻塞式調(diào)用, 否則性能可能受到嚴(yán)重影響又固。