resilience4j / resilience4j

Resilience4j is a fault tolerance library designed for Java8 and functional programming
Apache License 2.0
9.73k stars 1.33k forks source link

Open circuit when in flight http calls exceed slow call rate threshold with current time elapsed #1597

Open abhime42 opened 2 years ago

abhime42 commented 2 years ago

Resilience4j version: 1.3.1

Java version: 11

I would like to know whether is it possible to open a circuit even before receiving response for current in flight http requests to external service when the slow call duration and slow call rate threshold has been breached by these calls?

Example: slidingWindowType: TIME_BASED slidingWindowSize: 10 Minimun calls: 10 Slow call rate threshold: 50% Slow call duration threshold: 2 sec

Say t=0, we started 20 http requests to external service B ( no new requests till t=2 sec) t=2 sec, none of the requests has been completed

So already 2 sec has elapsed, and 100% of the requests has breached slow call duration threshold. Now I would like to open the circuit without having the need to wait for all requests to complete.

RobWin commented 2 years ago

Hi, no it's not possible with the CircuitBreaker alone. But you can use the TimeLimiter to timeout a call when the response time threshold has been exceeded.

abhime42 commented 2 years ago

@RobWin no I don't want to TimeLimit all the requests. It's a cause of concern only when total slow requests are above a certain threshold (say 20%, which is captured with slow call rate threshold).

So there is no way to open circuit based on in flight requests?

RobWin commented 2 years ago

No, right now there is no way.