【问题标题】:Hystrix & Ribbon Timeout WarningsHystrix 和 Ribbon 超时警告
【发布时间】:2018-11-10 08:53:35
【问题描述】:

环境

  • Spring Boot 1.5.13.RELEASE
  • Spring Cloud Edgware.SR3
  • 使用 Java 版本“1.8.0_172-ea”、Java(TM) SE 运行时环境(内部版本 1.8.0_172-ea-b03)和源代码级别 1.8 编译
  • 运行时 JRE:在带有 openjdk:10.0.1-jre-slim 的 docker 中

问题

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

serviceA.ribbon.ConnectTimeout=5000
serviceA.ribbon.ReadTimeout=15000
hystrix.command.serviceA.execution.isolation.thread.timeoutInMilliseconds = 20000

我没有(有意地)在类路径上获得 spring-retry。我执行./mvnw dependency:list | grep -i retry 并没有得到任何结果。

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

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

我不确定这些数字是从哪里来的,因为我认为我应该将它们分别设置为 15 秒和 5 秒。为什么这个数字是两倍?

【问题讨论】:

    标签: spring-cloud spring-cloud-netflix hystrix spring-cloud-feign netflix-ribbon


    【解决方案1】:

    实际上,ribbon timeout 包括所有相同服务器重试和下一个服务器重试。

    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.");
        }
    

    在您的配置中:

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

    所以 hystrixTimeout 应该是:

    (5000 + 15000) * (1 + 0) * (1 + 1) // -> 40000 ms
    

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

    19.13 Zuul Timeouts in Spring Cloud Document

    【讨论】:

      猜你喜欢
      • 2016-01-11
      • 2014-12-04
      • 2016-12-30
      • 2017-01-02
      • 1970-01-01
      • 2018-05-27
      • 2016-02-26
      • 2015-03-03
      • 2016-09-13
      相关资源
      最近更新 更多