0

I'm testing Spring Cloud circuit breaker and I'm missing the point of how actually "circuitBreaker.requestVolumeThreshold" parameter actually works...See my example...

@HystrixCommand(
            fallbackMethod = "invokeMicroServiceFallback",
            commandProperties = {
                @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",
                        value = "30000"),
                @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold",
                        value = "2"),
                @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds",
                        value = "500"),
                @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds",
                        value = "180000")
            },
            threadPoolProperties = {
                @HystrixProperty(name = "coreSize", value = "30"),
                @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds",
                        value = "180000")
            })
    public void invokeMicroService() {
        final RestTemplate restTemplate = new RestTemplate();

        final ServiceInstance serviceInstance = loadBalancer.choose("personsService");
        if (serviceInstance != null) {
            System.out.println("Invoking instance at URL: "+serviceInstance.getUri());
            System.out.println("Result :"+
                    restTemplate.getForObject(serviceInstance.getUri()+"/persons",
                            String.class));
        } else {
            System.out.println("Service is down...");
            throw new IllegalStateException("PersonsService is not running!");
        }
    }

    public void invokeMicroServiceFallback() {
        System.out.println("Waiting for circuit-breaker to close again...");
    }

If I turn the personsService down and invoke invokeMicroService in the loop then I've got a lot of output like:

First:

  Invoking instance at URL: <URL at my service>;
  "Waiting for circuit-breaker to close again..."

then after some time, just repeated:

  Service is down...
  "Waiting for circuit-breaker to close again..."

what circuitBreaker.requestVolumeThreshold actually does here? Why I have more than two attempts of trying to access personsService?

thanks in advance...

Tomas Kloucek
  • 251
  • 2
  • 12

1 Answers1

0

From the wiki https://github.com/Netflix/Hystrix/wiki/Configuration#circuitBreaker.requestVolumeThreshold

circuitBreaker.requestVolumeThreshold

This property sets the minimum number of requests in a rolling window that will trip the circuit.

For example, if the 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.

spencergibb
  • 24,471
  • 6
  • 69
  • 75