首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >circuitBreaker.requestVolumeThreshold不像预期的那样工作

circuitBreaker.requestVolumeThreshold不像预期的那样工作
EN

Stack Overflow用户
提问于 2016-11-06 21:43:37
回答 1查看 1.5K关注 0票数 0

我正在测试Spring断路器,我忽略了"circuitBreaker.requestVolumeThreshold“参数实际上是如何works...See我的例子的要点.

代码语言:javascript
复制
@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...");
    }

如果我关闭personsService并在循环中调用invokeMicroService,那么我得到了很多输出,比如:

第一:

代码语言:javascript
复制
  Invoking instance at URL: <URL at my service>;
  "Waiting for circuit-breaker to close again..."

过了一段时间后,我又重复了一遍:

代码语言:javascript
复制
  Service is down...
  "Waiting for circuit-breaker to close again..."

circuitBreaker.requestVolumeThreshold在这里到底做了什么?为什么我不止两次尝试访问personsService?

提前谢谢..。

EN

回答 1

Stack Overflow用户

发布于 2016-11-07 14:41:00

来自wiki https://github.com/Netflix/Hystrix/wiki/Configuration#circuitBreaker.requestVolumeThreshold

circuitBreaker.requestVolumeThreshold 此属性在滚动窗口中设置将触发电路的最小请求数。 例如,如果值为20,那么如果在滚动窗口(例如10秒的窗口)中只接收到19个请求,即使所有19个都失败了,电路也不会打开。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40454863

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档