mirror of
https://github.com/corda/corda.git
synced 2025-06-17 06:38:21 +00:00
Add jitter to retries (#3749)
* Add jitter to retries * Address comments
This commit is contained in:
@ -590,10 +590,11 @@ class SingleThreadedStateMachineManager(
|
|||||||
private fun scheduleTimeoutException(flow: Flow, retryCount: Int): ScheduledFuture<*> {
|
private fun scheduleTimeoutException(flow: Flow, retryCount: Int): ScheduledFuture<*> {
|
||||||
return with(serviceHub.configuration.flowTimeout) {
|
return with(serviceHub.configuration.flowTimeout) {
|
||||||
val timeoutDelaySeconds = timeout.seconds * Math.pow(backoffBase, retryCount.toDouble()).toLong()
|
val timeoutDelaySeconds = timeout.seconds * Math.pow(backoffBase, retryCount.toDouble()).toLong()
|
||||||
|
val jitteredDelaySeconds = maxOf(1L, timeoutDelaySeconds/2 + (Math.random() * timeoutDelaySeconds/2).toLong())
|
||||||
timeoutScheduler.schedule({
|
timeoutScheduler.schedule({
|
||||||
val event = Event.Error(FlowTimeoutException(maxRestartCount))
|
val event = Event.Error(FlowTimeoutException(maxRestartCount))
|
||||||
flow.fiber.scheduleEvent(event)
|
flow.fiber.scheduleEvent(event)
|
||||||
}, timeoutDelaySeconds, TimeUnit.SECONDS)
|
}, jitteredDelaySeconds, TimeUnit.SECONDS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,6 @@ rpcSettings = {
|
|||||||
}
|
}
|
||||||
flowTimeout {
|
flowTimeout {
|
||||||
timeout = 30 seconds
|
timeout = 30 seconds
|
||||||
maxRestartCount = 5
|
maxRestartCount = 6
|
||||||
backoffBase = 1.8
|
backoffBase = 1.8
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user