1

我偶然发现了throughput-deadline-timeAkka 调度程序的配置属性,它看起来是一个有趣的选项,但是我可以在整个文档中找到的唯一提及如下:

  # Throughput deadline for Dispatcher, set to 0 or negative for no deadline
  throughput-deadline-time = 0ms

我认为我们可以同意这不是很有帮助。

那么throughput-deadline-time控制是什么,它对我的​​调度员有什么影响?

4

1 回答 1

3

所以我看了一下Akka源代码,发现这个方法Mailbox似乎实现了以下行为throughput-deadline-time

/**
 * Process the messages in the mailbox
 */
@tailrec private final def processMailbox(
  left:       Int  = java.lang.Math.max(dispatcher.throughput, 1),
  deadlineNs: Long = if (dispatcher.isThroughputDeadlineTimeDefined == true) System.nanoTime + dispatcher.throughputDeadlineTime.toNanos else 0L):     Unit =
  if (shouldProcessMessage) {
    val next = dequeue()
    if (next ne null) {
      if (Mailbox.debug) println(actor.self + " processing message " + next)
      actor invoke next
      if (Thread.interrupted())
        throw new InterruptedException("Interrupted while processing actor messages")
      processAllSystemMessages()
      if ((left > 1) && ((dispatcher.isThroughputDeadlineTimeDefined == false) || (System.nanoTime - deadlineNs) < 0))
        processMailbox(left - 1, deadlineNs)
    }
  }

这段代码很清楚:throughput-deadline-time配置在切换到另一个参与者的邮箱之前处理同一个邮箱所花费的最长时间。

换句话说,如果您配置调度程序:

my-dispatcher {
  throughput = 100
  throughput-deadline-time = 1ms
}

然后参与者的邮箱一次最多处理 100 条消息,在最多 1 毫秒内,每当达到这些限制中的第一个时,Akka 就会切换到另一个参与者/邮箱。

于 2018-06-05T09:25:24.783 回答