OpenFeign/Hystrix 超时时间如何配置?
超时时间优先级:
Hystrix > Ribbon > OpenFeign
一、OpenFeign 超时时间
OpenFeign 超时时间配置:
feign:
circuitbreaker:
enabled: true
client:
config:
default:
connectTimeout: 3000
readTimeout: 3000
# feign日志级别,分别是:none、basic、headers、full
# full:请求和响应完整日志
loggerLevel: full
新版本的 OpenFeign 超时时间,如果不配置 OpenFeign 超时时间 ,connectTimeout 默认 10s,readTimeout 默认 60s,默认配置在Options() 方法中:
feign.Request.Options#Options()
二、Ribbon 超时时间
Ribbon超时时间配置:
# ribbon 的超时时间
ribbon:
ReadTimeout: 3000
ConnectTimeout: 3000
三、Hystrix 超时时间
Hystrix超时时间配置:
# hystrix 的超时时间
hystrix:
command:
default:
execution:
timeout:
enabled: true
isolation:
strategy: SEMAPHORE
semaphore:
maxConcurrentRequests: 100
thread:
timeoutInMilliseconds: 6000
线程隔离(isolation)
-
execution.isolation.strategy:
配置请求隔离的方式,有 threadPool(线程池,默认)和 semaphore(信号量)两种 -
execution.timeout.enabled
是否给方法执行设置超时,默认为 true。 -
execution.isolation.thread.timeoutInMilliseconds:
方法执行超时时间,默认值是 1000ms。 -
execution.isolation.thread.interruptOnTimeout / execution.isolation.thread.interruptOnCancel
是否在方法执行超时/被取消时中断方法。 -
execution.isolation.semaphore.maxConcurrentRequests
Hystrix 方法使用信号量隔离时的最大并发数,默认值是 10,此配置项要在execution.isolation.strategy
配置为semaphore
时才会生效,超过此并发数的请求会被拒绝。