昨天在部署環境的時候整個集群均為實例報錯,但是zuul的日志報錯
com.netflix.zuul.exception.ZuulException:Forwarding error
Caused by: java.lang.RuntimeException: java.net.SocketTimeoutException: Read timed out
Caused by: java.net.SocketTimeoutException: Read timed out
很明顯,根據報錯信息,應該是zuul的調用等待時間超時
在zuul中加入如下配置的簡化版
##timeout config hystrix: command: default: execution: timeout: enabled: true isolation: thread: timeoutInMilliseconds: 60000 ribbon: ReadTimeout: 60000 ConnectTimeout: 60000 MaxAutoRetries: 0 MaxAutoRetriesNextServer: 1 eureka: enabled: false zuul: max: host: connections: 500 host: socket-timeout-millis: 60000 connect-timeout-millis: 60000
該配置中也包括了集群中單個實例報錯,控制zuul調用其它實例的方法(嘗試重新調用集群中服務器的數量,和超時后對本實例的再次重試次數)
同時在fegin的調用端也要用對應的ribbon和hystrix的配置,用來覆蓋其默然配置的三秒超時時間,因為每次服務器重新啟動之后,初次訪問實例初始話的過程中比較耗時,所以在初次訪問的時候超時的概率很大,
所以需要加上次配置抵消容器初始話后首次調用的超時現象。
對於首次調用超時的情況,還可以設置對應的feign.hystrix.enabled=false,默認去關閉hystrix的功能也是可以的,但是不推薦,尤其是生產環境