Avoid the pit Guide (VI): Hystrix timeout less than the ribbon timeout error

Problem

zuul configuration is as follows:

server:
  port: 5566
​
zuul:
  prefix: /gateway
  sensitive-headers:
  routes:
    auth:
      path: /auth/**
      service-id: xmall-auth
      strip-prefix: true
    product:
      path: /product/**
      service-id: xmall-product
      strip-prefix: true
  ribbon-isolation-strategy: thread
​
hystrix:
  command:
    default:
      execution:
        isolation:
          strategy: THREAD
          thread:
            timeoutInMilliseconds: 70000
​
​
# ribbon配置
ribbon:
  MaxConnectionsPerHost: 300
  MaxTotalConnections: 1000
  ConnectTimeout: 60000
  ReadTimeout: 60000
#  MaxAutoRetries: 1
#  MaxAutoRetriesNextServer: 1
​
management:
  endpoints:
    web:
      exposure:
        include: '*'

However, when the system is started, or visit zuul, there is always reported the following error:

The Hystrix timeout of 70000ms for the command xxx is set lower than the combination of the Ribbon read and connect time, 240000ms。

 

analysis

Ribbon total timeout calculated as:

RibbonTimeout = (RibbonReadTimeout + RibbonConnectTimeout) × (MaxAutoRetries + 1) × (MaxAutoRetriesNextServer + 1)

If the problem is configured, then the total Ribbon timeout to:

RibbonTimeout = (60000 + 60000) × (0 + 1) × (1 + 1) = 240000ms。

This value, and the error message 240000ms match.

Unfortunately, Hystrix timeout is 70000ms, less than Ribbon timeout 240000ms. Logically, HystrixTimeout must be greater than RibbonTimeout. Because Hystrix Once open fuse, Ribbon retry will not have any meaning.

 

solve

The solution is simple, Hystrix configured timeout timeout than the Ribbon can be large, you may also lower the Ribbon ReadTime, Connect Time, the number of retries and other parameters.

server:
  port: 5566
​
zuul:
  prefix: /gateway
  sensitive-headers:
  routes:
    auth:
      path: /auth/**
      service-id: xmall-auth
      strip-prefix: true
    product:
      path: /product/**
      service-id: xmall-product
      strip-prefix: true
  ribbon-isolation-strategy: thread
​
hystrix:
  command:
    default:
      execution:
        isolation:
          strategy: THREAD
          thread:
            timeoutInMilliseconds: 300000
​
​
# ribbon配置
ribbon:
  MaxConnectionsPerHost: 300
  MaxTotalConnections: 1000
  ConnectTimeout: 60000
  ReadTimeout: 60000
#  MaxAutoRetries: 1
#  MaxAutoRetriesNextServer: 1
​
management:
  endpoints:
    web:
      exposure:
        include: '*'

The timeout Hystrix configured 300000ms, greater than Ribbon timeout 240000ms.

 

 

This article is [Galaxy] original architect, in an article for reprint please indicate the author and source of the obvious.

Micro-channel search [architect] Galaxy, find more exciting content.

 

发布了29 篇原创文章 · 获赞 1 · 访问量 2223

Guess you like

Origin blog.csdn.net/liuminglei1987/article/details/104200256