简体   繁体   中英

Resilience4J Circuitbreaker Configs not working properly

I am trying to build a Resilience4J Circuitbreaker using custom CircuitbreakerConfig

Using the following code to build CircuitbreakerConfig

CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig
    .custom()
    .slidingWindowSize(100)
    .failureRateThreshold(50)
    .slowCallRateThreshold(50)
    .slowCallDurationThreshold(
        Duration.ofMillis(1000))
    .waitDurationInOpenState(
        Duration.ofMillis(1000))
    .recordExceptions(IOException.class,
        FeignException.FeignServerException.ServiceUnavailable.class)
    .ignoreExceptions(
        FeignException.FeignServerException.InternalServerError.class)
    .build();
CircuitBreaker circuitBreaker = CircuitBreaker.of("sample-cb", circuitBreakerConfig);

I am using this to make a HTTP Call. Which always takes more than 1000 milliseconds to respond. Ideally, CircuitBreaker should transition to OPEN state if 50 if first 100 calls are slow. But it is transitioning to OPEN state only after 100 calls.

Not able to understand this behaviour. Looking for help.

It's because the default value of minimumNumberOfCalls is 100.

The failure rate and slow call rate can only be calculated, if a minimum number of calls were recorded. For example, if the minimum number of required calls is 10, then at least 10 calls must be recorded, before the failure rate can be calculated. If only 9 calls have been evaluated the CircuitBreaker will not trip open even if all 9 calls have failed.

You can set it to 50.

Remove failureRateThreshold as a test, my assumption is that it is considering a sum between failureRateThreshold and slowCallRateThreshold to take effect

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM