Hystrix和功能区超时警告

Dav*_*vid 2 hystrix spring-cloud spring-cloud-feign netflix-ribbon spring-cloud-netflix

环境

  • Spring Boot 1.5.13。发布
  • Spring Cloud Edgware.SR3
  • 与Java版本“ 1.8.0_172-ea”,Java™SE运行时环境(内部版本1.8.0_172-ea-b03)和源代码级别1.8一起编译
  • 运行时JRE:在docker中 openjdk:10.0.1-jre-slim

我有一个名为serviceA并关联的功能区客户端

serviceA.ribbon.ConnectTimeout=5000
serviceA.ribbon.ReadTimeout=15000
hystrix.command.serviceA.execution.isolation.thread.timeoutInMilliseconds = 20000
Run Code Online (Sandbox Code Playgroud)

我还没有(知道)在类路径上进行spring-retry。我执行./mvnw dependency:list | grep -i retry并没有结果。

在运行时,我收到以下警告:

命令serviceA的Hystrix超时20000ms设置为小于功能区读取和连接超时的组合40000ms。

考虑到我认为分别将它们设置为15秒和5秒,因此我不确定这些数字来自何处。为什么这个数字翻倍?

boo*_*oon 11

实际上,功能区超时包括所有相同的服务器重试和下一个服务器重试。

ribbonTimeout = (ribbon.ConnectTimeout + ribbon.ReadTimeout) * (ribbon.MaxAutoRetries + 1) * (ribbon.MaxAutoRetriesNextServer + 1);
// ...
if(hystrixTimeout < ribbonTimeout) {
        LOGGER.warn("The Hystrix timeout of " + hystrixTimeout + "ms for the command " + commandKey +
            " is set lower than the combination of the Ribbon read and connect timeout, " + ribbonTimeout + "ms.");
    }
Run Code Online (Sandbox Code Playgroud)

在您的配置中:

  • ribbon.connectionTimeout为5000
  • ribbon.readTimeout是15000
  • ribbon.maxAutoRetries为0(默认)
  • ribbon.maxAutoRetriesNextServer为1(默认)

因此hystrixTimeout应该是:

(5000 + 15000) * (1 + 0) * (1 + 1) // -> 40000 ms
Run Code Online (Sandbox Code Playgroud)

如果您选择不配置Hystrix超时,则默认的Hystrix超时将为40000ms。

19.13 Spring Cloud文档中的Zuul超时