"throughput-deadline-time" 配置选项有什么作用?
What does the "throughput-deadline-time" configuration option do?
我偶然发现了 Akka 调度程序的 throughput-deadline-time
配置 属性,它看起来是一个有趣的选项,但是我在整个文档中唯一提到的是以下内容:
# Throughput deadline for Dispatcher, set to 0 or negative for no deadline
throughput-deadline-time = 0ms
我想我们都同意这不是很有帮助。
那么 throughput-deadline-time
控制什么,它对我的调度程序有什么影响?
所以我看了一下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
}
然后 actors 的邮箱一次最多处理 100 条消息,最多 1 毫秒,只要达到第一个限制,Akka 就会切换到另一个 actor/mailbox。
我偶然发现了 Akka 调度程序的 throughput-deadline-time
配置 属性,它看起来是一个有趣的选项,但是我在整个文档中唯一提到的是以下内容:
# Throughput deadline for Dispatcher, set to 0 or negative for no deadline
throughput-deadline-time = 0ms
我想我们都同意这不是很有帮助。
那么 throughput-deadline-time
控制什么,它对我的调度程序有什么影响?
所以我看了一下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
}
然后 actors 的邮箱一次最多处理 100 条消息,最多 1 毫秒,只要达到第一个限制,Akka 就会切换到另一个 actor/mailbox。