The Hystrix timeout of 20000ms for the command uaa-service is set lower than the combination of the

Zuul的配置如下:

server:
  port: 8000

spring:

# 单机
#  redis:
#    host: 192.168.124.100
#    password:
#    port: 6379
# 集群
  redis:
    database: 0
    cluster:
      nodes:
        - 192.168.111.192:6380
        - 192.168.111.192:6381
        - 192.168.111.192:6382
        - 192.168.111.192:6383
        - 192.168.111.192:6384
        - 192.168.111.192:6385
    jedis:
      pool:
        max-idle: 8
        min-idle: 0
        max-active: 8
        max-wait: -1
    timeout: 10000

  zipkin:
    base-url: http://localhost:8004
  sleuth:
    sampler:
      percentage: 1.0

eureka:
  instance:
    prefer-ip-address: true
    leaseRenewalIntervalInSeconds: 10
    health-check-url-path: /actuator/health
  client:
    registryFetchIntervalSeconds: 5
    serviceUrl:
      defaultZone: http://localhost:8001/eureka/

#网关
zuul:
  ribbon:
    eager-load:
      enabled: true #zuul饥饿加载
  host:
    max-total-connections: 200
    max-per-route-connections: 20
    #以下两个配置也是解决zuul超时的
    #和使用ribbon.ReadTimeout的区别是,如果路由配置使用service-id的方式,那么ribbon.ReadTimeout生效,如果使用url的方式,此配置生效
    connect-timeout-millis: 10000
    socket-timeout-millis: 10000
  routes:
    uaa-service:
      path: /uaa/**
      serviceId: uaa-service
    code-service:
      path: /code/**
      serviceId: code-service
    user-service:
      path: /user/**
      serviceId: user-service
    order-service:
      path: /order/**
      serviceId: order-service
  #解决Authorization请求头丢失的问题
  sensitive-headers:

#配置Ribbon的超时时间
ribbon:
  ReadTimeout: 10000
  ConnectTimeout: 10000
#  MaxAutoRetries: 1
#  MaxAutoRetriesNextServer: 1

hystrix:
  command:
    default:
      execution:
        isolation:
          strategy: SEMAPHORE
          #配置hystrix的超时时间
          thread:
            timeoutInMilliseconds: 20000

#Admin Client,暴露自己的actuator的所有端口信息
management:
  endpoints:
    web:
      exposure:
        exposure: '*'
  endpoint:
    health:
      show-details: ALWAYS

访问的时候提示错误:

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

分析:

Ribbon 总超时时间计算公式如下:

ribbonTimeout = (RibbonReadTimeout + RibbonConnectTimeout) * (MaxAutoRetries + 1) * (MaxAutoRetriesNextServer + 1)

其中,MaxAutoRetries 默认为0,MaxAutoRetriesNextServer 默认为1,所以我这里的具体值为:(10000+10000)*(0+1)*(1+1)=40000。

而 Hystrix 超时时间为 20000 < 40000,从逻辑上来讲,hystrixTimeout 要大于 ribbonTimeout,否则 hystrix 熔断了以后,ribbon 的重试就都没有意义了。

所以,这个问题很简单,要么配置hystrix的超时时间不小于40000,如下:

ribbon:
  ReadTimeout: 10000
  ConnectTimeout: 10000
#  MaxAutoRetries: 1
#  MaxAutoRetriesNextServer: 1

hystrix:
  command:
    default:
      execution:
        isolation:
          strategy: SEMAPHORE
          #配置hystrix的超时时间,要大于(RibbonReadTimeout + RibbonConnectTimeout) * (MaxAutoRetries + 1) * (MaxAutoRetriesNextServer + 1)
          thread:
            timeoutInMilliseconds: 40000

要么调低 ribbon 的 timeOut 或者重试次数。

参考:

https://www.cnblogs.com/jizhong/p/11551797.html

https://blog.csdn.net/akaks0/article/details/80039590

https://blog.csdn.net/lidew521/article/details/84661158

发布了114 篇原创文章 · 获赞 91 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qmqm011/article/details/101455917