Hystrix circuitBreaker.sleepWindowInMilliseconds not working
I have a spring boot application that iteratively calls a mockserver instance via the hystrix command using a return method.
The mockserver is configured to always respond with a 500 status code. When started without using circuitBreaker.sleepWindowInMilliseconds, everything works fine, the call is made in the mockserver and then the backup method is called.
After setting circuitBreaker.sleepWindowInMilliseconds to 5 minutes or so, I would expect no calls to the mockserver to be made for 5 minutes, all calls to the fallback method, but this is not the case.
It looks like the circuitBreaker.sleepWindowInMilliseconds configuration is being ignored.
For example, if I reconfigure the mockservice to respond with a 200 status code while the iteration is still running, it will immediately return a "mockservice response" without waiting 5 minutes.
in the main class of spring boot application:
@RequestMapping("/iterate")
public void iterate() {
for (int i = 1; i<100; i++ ) {
try {
System.out.println(bookService.readingMockService());
Thread.sleep(3000);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
in spring boot service:
@HystrixCommand(groupKey = "ReadingMockService", commandKey = "ReadingMockService", threadPoolKey = "ReadingMockService", fallbackMethod = "reliableMock", commandProperties = {
@HystrixProperty(name ="circuitBreaker.sleepWindowInMilliseconds", value = "300000") })
public String readingMockService() {
URI uri = URI.create("http://localhost:1080/askmock");
return this.restTemplate.getForObject(uri, String.class);
}
also the server layout runs on the same machine, configurable as:
new MockServerClient("127.0.0.1", 1080).reset();
new MockServerClient("127.0.0.1", 1080)
.when(request("/askmock"))
.respond(response()
.withStatusCode(500)
.withBody("mockservice response")
.applyDelay());
source to share
From the docs: https://github.com/Netflix/Hystrix/wiki/configuration#circuitBreaker.sleepWindowInMilliseconds
and looking at the source code:
Using
@HystrixProperty(name="hystrix.command.ReadingMockService.circuitBreaker.sleepWindowInMilliseconds"
must work.
source to share
Problem encountered: This property (... circuitBreaker.sleepWindowInMilliseconds) works in conjunction with another (... circuitBreaker.requestVolumeThreshold). Unless specifically set, this default is 20, which means that the first histria will try to connect 20 times in the normal way, and only after that sleepWindowInMilliseconds will be activated and will only return.
Also, a circuit break is opened only if the percentage of failed calls exceeds the value of circuitBreaker.errorThresholdPercentage and at the same time the total number of failed calls exceeds circuitBreaker.requestVolumeThreshold, all within the metrics.rollingStats.timeInMilliseconds window
source to share