Hystrix Configuration
How Hystrix Circuit-Breaker operates: Hystrix does not offer a circuit breaker which breaks after a given number of failures. The Hystrix circuit will break if:
within a timespan of duration
metrics.rollingStats.timeInMilliseconds
, the percentage of actions resulting in a handled exception exceedserrorThresholdPercentage
, provided also that the number of actions through the circuit in the timespan is at leastrequestVolumeThreshold
What is requestVolumeThreshold?
requestVolumeThreshold
is a minimum threshold for the volume (number) of calls through the circuit that must be met (within the rolling window), before the circuit calculates a percentage failure rate at all. Only when this minimum volume (in each time window) has been met, will the circuit compare the failure proportion of your calls against the errorThresholdPercentage
you have configured.
Imagine there was no such minimum-volume-through-the-circuit threshold. Imagine the first call in a time window errors. You would have 1 of 1 calls being an error, = 100% failure rate, which is higher than the 50% threshold you have set. So the circuit would break immediately.
The requestVolumeThreshold
exists so that this does not happen. It's effectively saying, the error rate through your circuit isn't statistically significant (and won't be compared against errorThresholdPercentage
) until at least requestVolumeThreshold
calls have been received in each time window.
I am rather new to hystrix but I guess I can help you.
In general hystrix.command.default.circuitBreaker.requestVolumeThreshold
is a property that sets the minimum number of requests in a rolling window that will trip the circuit and its default value is 20 and its value can be changed in properties file or in our @HystrixCommand
annotated method.
For example, if that property value is 20, then if only 19 requests are received in the rolling window (say a window of 10 seconds) the circuit will not trip open even if all 19 failed. If the failed request value reaches 20, then the circuit will be opened and the corresponding calls will be sent to fallback even if the call succeeds, till the sleeping window time period complete.
Sleeping window time period sets the amount of time, after tripping the circuit, to reject requests before allowing attempts again to determine if the circuit should again be closed. Its value is defaulted to 5000 milliseconds. This can be changed by overriding circuitBreaker.sleepWindowInMilliseconds
property.
You can find all the properties and its description here.