Add jitter to retries (#3749)

* Add jitter to retries

* Address comments
This commit is contained in:
Thomas Schroeter 2018-08-07 13:24:22 +01:00 committed by GitHub
parent 6255459ce7
commit dd4923e80e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -590,10 +590,11 @@ class SingleThreadedStateMachineManager(
private fun scheduleTimeoutException(flow: Flow, retryCount: Int): ScheduledFuture<*> {
return with(serviceHub.configuration.flowTimeout) {
val timeoutDelaySeconds = timeout.seconds * Math.pow(backoffBase, retryCount.toDouble()).toLong()
val jitteredDelaySeconds = maxOf(1L, timeoutDelaySeconds/2 + (Math.random() * timeoutDelaySeconds/2).toLong())
timeoutScheduler.schedule({
val event = Event.Error(FlowTimeoutException(maxRestartCount))
flow.fiber.scheduleEvent(event)
}, timeoutDelaySeconds, TimeUnit.SECONDS)
}, jitteredDelaySeconds, TimeUnit.SECONDS)
}
}

View File

@ -22,6 +22,6 @@ rpcSettings = {
}
flowTimeout {
timeout = 30 seconds
maxRestartCount = 5
maxRestartCount = 6
backoffBase = 1.8
}