一、問題原因
Gateway ribbon 超時時間設置
ribbon:
#Ribbon允許最大連接數,即所有後端微服務實例請求併發數之和的最大值。
MaxTotalConnections: 500
#單個後端微服務實例能接收的最大請求併發數
MaxConnectionsPerHost: 500
ReadTimeout: 2000
ConnectTimeout: 2000
# 關閉Ribbon的重試機制
MaxAutoRetriesNextServer: 0 #慎用
hystrix:
threadpool:
default:
coreSize: 20 #併發執行的最大線程數,默認10
maxQueueSize: 500 #BlockingQueue的最大隊列數,默認值-1
queueSizeRejectionThreshold: 500 #即使maxQueueSize沒有達到,達到queueSizeRejectionThreshold該值後,請求也會被拒絕,默認值5
command:
default:
execution:
timeout:
#如果enabled設置爲false,則請求超時交給ribbon控制
enabled: false
此時調用auth模塊驗證token,auth模塊調用customer模塊查詢用戶,此時設置ribbon read時間也是2秒
ReadTimeout: 2000
調用接口出現問題,2.647秒超過了2秒
poc-auth-service.post /auth/checktoken: 2.647s
Key Value
error Read timed out
二、解決方法
因爲首次系統加載需要額外時間,第一次時間會比較久,儘量設置折中的時間。
Gateway超時時間設置長些 ,解決問題
ReadTimeout: 4000
網上說,加上以下ribbon初始化,會減少消耗時間,但是我測了沒效果
#從Dalston開始,Ribbon支持配置eager load實現在啓動時就初始化Ribbon相關類。
eager-load:
enabled: true
clients: client1, client2, client3