spring-cloud - Hystrix 和 Ribbon 超时警告

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

环境

  • 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:在 docker 中使用 openjdk:10.0.1-jre-slim



  • 我有一个名为 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并没有得到任何结果。

    在运行时,我收到这些警告:

    The Hystrix timeout of 20000ms for the command serviceA is set lower than the combination of the Ribbon read and connect timeout, 40000ms.



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

    最佳答案

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

    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 超时将为 40000 毫秒。

    19.13 Zuul Timeouts in Spring Cloud Document

    关于spring-cloud - Hystrix 和 Ribbon 超时警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50622668/

    相关文章:

    kubernetes - Hystrix-dashboard 无法与 Kubernetes 上的 Kubeflix 配合使用

    java - Hystrix 仪表板不工作

    Spring Cloud RefreshScope 刷新后 Hook

    spring-cloud - 如何向 Spring Cloud Bootstrap 添加功能

    java - 我可以仅使用 Zuul 后置过滤器获取请求的响应时间吗?

    spring - 功能区负载均衡算法

    Spring Cloud Zuul + OAuth 错误 CORS

    grails - hystrix Fallback不会针对集合中的单个项目进行调用

    Spring-Cloud、Hystrix 和 JPA - LazyInitializationException