question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calculated break duration for Circuit breaker and Advance Circuit breaker

See original GitHub issue

CircuitBreaker 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:open
  • Created 4 years ago
  • Reactions:2
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
martintmkcommented, Jul 20, 2023

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

public abstract class CircuitBreakerStrategyOptions<TResult>
{
   public Func<BreakDurationGeneratorArguments, ValueTask<TimeSpan>>? BreakDurationGenerator { get; set; }
}

It will be optional generator that can override the fixed BreakDuration.

1reaction
reisenbergercommented, Jun 13, 2019

( Courtesy reply: commitments mean I may not get to respond to this until next week. Thanks. )

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Polly Circuit Breakers for Resilient .NET Web ...
This is the Advanced Circuit Breaker policy: the circuit will be cut if 25% of requests fail in a 60 second window, with...
Read more >
6 Adjustable Tripping Settings of a Circuit Breaker You ...
The adjustment is from 2.2 to 27 seconds at six times the continuous amps (Ir) setting. As shown below, the long-time delay effects...
Read more >
Circuit breakers (beta) - Monte Carlo
Circuit breakers can be used to stop (or “circuit break”) pipelines when data does not meet a set of quality or integrity thresholds....
Read more >
Circuit breaker settings | Elasticsearch Guide [8.9]
Elasticsearch calculates this limit by multiplying the setting value by the script input's character length. For example, the input foobarbaz has a character ......
Read more >
Circuit Breaker
The market index percentage changes were split into three tiers. Level 1 tier sets up a threshold of 7% decline, level 2 circuit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found