項目中出現了設置了hystrix超時時間,依舊很快就發生了超時異常的狀況。java
You can use semaphores (or counters) to limit the number of concurrent calls to any given dependency, instead of using thread pool/queue sizes. This allows Hystrix to shed load without using thread pools but it does not allow for timing out and walking away. If you trust the client and you only want load shedding, you could use this approach.
官方文檔裏面指出使用信號量,沒法設置超時。app
而咱們的項目中有出現,存在超時時間和信號量同時配置的狀況。這個時候配置超時時間是不起效的。
this
設置了隔離隔離策略是SEMAPHORE
,仍是出現了超時現象。
![d151cd7c3f4f029a6dfdf135ab5d2bfe.png](evernotecid://FD991630-9A29-41DC-9C96-99ADAD4D5D74/appyinxiangcom/13442185/ENResource/p4775)spa
通過排查是ribbon超時。ribbon.ConnectTimeout
和 ribbon.ReadTimeout
默認超時時間都只有1000毫秒。code
// ribbon的超時時間計算 ribbonTimeout = (ribbon.ConnectTimeout + ribbon.ReadTimeout) * (ribbon.MaxAutoRetries + 1) * (ribbon.MaxAutoRetriesNextServer + 1)
hystrixTimeout要大於ribbonTimeout,不然hystrix
熔斷了之後,ribbon
的重試就都沒有意義了。而當feign設置了超時時間,Ribbon
會依據feign
的connectTimeout
設置同步。blog
因此正確的超時時間設置應該是:ci
hystrixTimeout > ribbonTimeout
。feignConnectTimeout > ribbonTimeout