Timeout times to retry SpringCloud Feign of inquiry

Timeout times to retry SpringCloud Feign of inquiry

The last article, we have an initial experience Feign a fallback, where we look back, Fallback is mainly used to solve the dependent services are not available or call the service fails or a timeout, use the default return value. Practical application, before Fallback, you need to configure the service retry mechanism, in the case where multiple retries service, or a service unavailable, triggered Fallback.

Here, we configured to retry mechanism as well as the number of retries once explored.

Feign timeout

Feign interface calls divided into two levels, calling Ribbon (load balancing) and Hystrix (fuse), so Feign-out time is

ribbon timeout and a timeout Hystrix the binding (not a simple sum).

##hystrix的超时时间
hystrix:
  command:
    default:
      execution:
        timeout:
          enabled: true
        isolation:
          thread:
            timeoutInMilliseconds: 60000
##Ribbon超时
ribbon:
  ConnectTimeout: 20000  #毫秒    连接超时时间
  ReadTimeout: 20000     #毫秒      逻辑处理超时时间

Under normal circumstances, since there are Ribbon retry mechanism, so Ribb timeout is <Hystrix blown out.

Feign retry

Retry mechanism Feign in the source code off by default, because retry mechanism Ribbon and Fiegn conflict original retry mechanism, so in general, retry mechanism Feign refers to is the retry mechanism Ribbon, the paper also true .

Ribbon timeout Retry
##Ribbon超时重试配置
ribbon:
  ConnectTimeout: 20000  #毫秒    连接超时时间
  ReadTimeout: 20000     #毫秒      逻辑处理超时时间
  OkToRetryOnAllOperations: true    # 是否对所有操作都进行重试
  MaxAutoRetries: 2     # 对当前实例的最大重试次数(请求服务超时6s则会再请求一次)
  MaxAutoRetriesNextServer: 1     # 切换实例的最大重试次数(如果还失败就切换下

Ribbon timeout retries (the total number of requests): ** (MaxAutoRetries + 1) * (MaxAutoRetriesNextServer + 1) **

Ribbon If no retry number and configuration, the default 1S timeout, retry default 1 .

Retries verification
  • Set the timeout 2S, in the demo sleep 3S, will find the requested 6 times.

  • And not the number of retries to time, sleep 3S, retry 1 times, 2 times a total request.

    According to test results, the conclusion can be seen correctly. The total number of requests): ** (MaxAutoRetries + 1) * (MaxAutoRetriesNextServer + 1) **

other
  • If during the retry, calls for more than the timeout Hystrix fuse, the fuse will immediately be FallBack.

    The above description can be substantially calculated timeout can Hystrix reference, may be used to hold the retry mechanism.

    hystrix超时时间的计算:(MaxAutoRetries+1)(MaxAutoRetriesNextServer+1) (ConnectTimeout+ReadTimeout) 。

  • 当ribbon超时后且hystrix没有超时,就会使用到重试机制。

  • 默认情况下,GET方式请求无论是连接异常还是读取异常,都会进行重试,非GET方式请求,只有连接异常时,才会进行重试(从其他博文学习到,暂未验证)

  • demo地址:https://github.com/lanxuan826/sample-library/tree/master/feigndemo-fallback

Guess you like

Origin www.cnblogs.com/lanxuan826/p/11617903.html