Calculated break duration for Circuit breaker and Advance Circuit breaker
See original GitHub issueCircuitBreaker and AdvanceCircuitBreaker currently only allow for a fixed break duration. I would like to be able to calculated the break duration based on the number of consecutive “unhealthy” requests made. This would allow the duration to be increased as the downstream system continues to be unavailable. With this I would be able to increase the duration between attempts to interact with the downstream system over time hopefully allowing it to recover. With this I would also be able to reduce log entries for failed requests to the downstream service.
The use case I see for this is a system that is going to be down for awhile do to some catastrophic issue. Like the Retry policy this allows us to wait longer each time before attempting to interact with the system, and using Math.Min allows us to set an upper limit on the wait duration.
Example Usage
Policy.Handle<Exception>().CircuitBreaker(
exceptionsAllowedBeforeBreaking: 5,
durationOfBreak: unhealthyAttempts => TimeSpan.FromSeconds(Math.Min(20 + Math.Pow(2, unhealthyAttempts), /* Max */400)));
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:10 (10 by maintainers)
Top GitHub Comments
Currently not, but it’s easy enough to add post V8 release.
https://github.com/App-vNext/Polly/blob/dd14ca630b7614955580e7b26e0adc56f653c694/src/Polly.Core/CircuitBreaker/CircuitBreakerStrategyOptions.cs#L34
It will be optional generator that can override the fixed
BreakDuration
.( Courtesy reply: commitments mean I may not get to respond to this until next week. Thanks. )