zuul服务器的配置maxSemaphores

时间:2017-06-14 11:53:08

标签: netflix-zuul spring-cloud-netflix hystrix

我正在尝试为zuul version 1.1.2进行负载测试。

但是,运行负载测试后,我会在几分钟后继续跟进问题。

Caused by: com.netflix.hystrix.exception.HystrixRuntimeException: book could not acquire a semaphore for execution and no fallback available.
    at com.netflix.hystrix.AbstractCommand$21.call(AbstractCommand.java:783) ~[hystrix-core-1.5.3.jar:1.5.3]

我的问题是如何通过混淆来增加maxSemaphores

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds= 20000000
zuul.hystrix.command.default.execution.isolation.strategy= SEMAPHORE
zuul.hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests= 10
zuul.hystrix.command.default.fallback.isolation.semaphore.maxConcurrentRequests= 10
zuul.semaphore.maxSemaphores=3000

zuul.eureka.book.semaphore.maxSemaphore = 30000

我已尝试在Intenet上搜索多个选项,但其中一个适用于我

请告知

3 个答案:

答案 0 :(得分:1)

我可以为特定的server_id' 预订'配置zuul.eureka.book.semaphore.maxSemaphores=30000 如下:

zuul.eureka.default.semaphore.maxSemaphores=30000

但是,我想为所有功能区客户端路由到后端微服务设置默认值,如下所示

protected static HystrixCommand.Setter getSetter(String commandKey) {
        // we want to default to semaphore-isolation since this wraps
        // 2 others commands that are already thread isolated
        String name = ZuulConstants.ZUUL_EUREKA + commandKey + ".semaphore.maxSemaphores";
        DynamicIntProperty value = DynamicPropertyFactory.getInstance().getIntProperty(
                name, 100);
        HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
                .withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE)
                .withExecutionIsolationSemaphoreMaxConcurrentRequests(value.get());
        return Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RibbonCommand"))
                .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey))
                .andCommandPropertiesDefaults(setter);
    }

但它没有任何效果。

我还检查了 RestClientRibbonCommand 类的代码,有趣的是它只支持server_id。

代码段

network.host: [ "127.0.0.1" ]
network.host: [ "_local_" ]
network.host: [ "_lo_" ]
由于Zuul意味着动态路由所以非常奇怪,所以我不想为每一项服务配置。

请指教?

答案 1 :(得分:0)

事实证明我使用的是旧版本。对于更高版本,我们可以在Zuul级别设置信号量。下面是将maxSemaphores 3000设置为路由到每个代理服务的默认值

的示例

<强> zuul.semaphore.maxSemaphores = 3000

答案 2 :(得分:0)

实际属性是max-semaphores(这将是yaml配置):

zuul:
  semaphore:
    #com.netflix.hystrix.exception.HystrixRuntimeException: "microservice" could not acquire a semaphore for execution and no fallback available.
    max-semaphores: 2000