【问题标题】:What is the correct way to configure actors in Play 2.x?在 Play 2.x 中配置演员的正确方法是什么?
【发布时间】:2013-05-06 15:06:41
【问题描述】:

我注意到 2.1 和 2.0 的文档略有不同:

2.0

akka.default-dispatcher.core-pool-size-max = 64
akka.debug.receive = on

2.1

akka.default-dispatcher.fork-join-executor.pool-size-max =64
akka.actor.debug.receive = on

Akka's own documentation 具有类似 2.0 的 core-pool-size-max 设置,但没有类似 2.1 的 pool-size-max。为什么这在 2.0 和 2.1 之间发生了变化?在 Play 中配置 Akka 的正确方法是什么?这是其中一个版本中的文档错误吗?

(与此同时,我将尝试在我的 Play 2.1 配置中保留这两种配置样式,并希望最好)。

【问题讨论】:

    标签: scala playframework playframework-2.0 akka playframework-2.1


    【解决方案1】:

    首先,始终使用您正在使用的版本的文档,在您的情况下,您将链接到未发布的 Akka 版本(即快照)的快照文档。

    这是 2.1.2 文档:http://doc.akka.io/docs/akka/2.1.2/scala/dispatchers.html(也可从 doc.akka.io 访问)

    当我们查看该页面时,我们看到在 fork-join-executor 和 thread-pool-executor 的 example 配置下它说:“有关更多选项,请参阅 default-dispatcher 部分的配置。”,链接到:

    我们在哪里可以找到:

      # This will be used if you have set "executor = "thread-pool-executor""
      thread-pool-executor {
        # Keep alive time for threads
        keep-alive-time = 60s
    
        # Min number of threads to cap factor-based core number to
        core-pool-size-min = 8
    
        # 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 = 64
    
        # Minimum number of threads to cap factor-based max number to
        # (if using a bounded task queue)
        max-pool-size-min = 8
    
        # 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 = 64
    
        # Specifies the bounded capacity of the task queue (< 1 == unbounded)
        task-queue-size = -1
    
        # Specifies which type of task queue will be used, can be "array" or
        # "linked" (default)
        task-queue-type = "linked"
    
        # Allow core threads to time out
        allow-core-timeout = on
      }
    

    总而言之,如果您想使用 ThreadPoolExecutor,则需要通过akka.default-dispatcher.executor = "thread-pool-executor" 将默认调度程序设置为使用"thread-pool-executor",然后为该线程池执行程序指定您的配置。

    这有帮助吗?

    干杯, √

    【讨论】:

    • Amm,我不想更改执行程序,只需按照 Play 配置中的示例调整默认执行程序 - 我只是想知道为什么 Play 2.1 的文档与 Play 2.0 不同 - 是否这是一个真正的 API 更改,或者如果这是一个文档错误。无论如何,我只想设置core-pool-size-maxpool-size-max
    • 但是您需要更改设置以进行正确的实施。默认调度程序使用 fork-join-executor,因此除非您更改执行程序,否则您必须更改设置。请参阅文档。
    猜你喜欢
    • 1970-01-01
    • 2016-05-07
    • 1970-01-01
    • 2010-11-24
    • 2010-10-21
    • 1970-01-01
    • 1970-01-01
    • 2013-05-28
    • 2012-03-18
    相关资源
    最近更新 更多