[翻譯]squbs官網(wǎng)之12 阻塞式調(diào)度器

用于阻塞式API調(diào)用的阻塞式調(diào)度器

本主題不是關(guān)于一般的調(diào)度器,而是關(guān)于squbs特定的調(diào)度器配置。請查看Akka 文檔中關(guān)于調(diào)度器的詳細信息。

squbs增加了另外一個預定義的調(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)度器只能應用于阻塞式調(diào)用, 否則性能可能受到嚴重影響。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容