spring cloud zuul參數調優


zuul 內置參數

zuul.host.maxTotalConnections

適用於ApacheHttpClient,如果是okhttp無效。每個服務的http客戶端連接池最大連接,默認是200.

zuul.host.maxPerRouteConnections

適用於ApacheHttpClient,如果是okhttp無效。每個route可用的最大連接數,默認值是20。

zuul.semaphore.max-semaphores

Hystrix最大的並發請求execution.isolation.semaphore.maxConcurrentRequests,這個值並非TPSQPSRPS等都是相對值,指的是1秒時間窗口內的事務/查詢/請求,semaphore.maxConcurrentRequests是一個絕對值,無時間窗口,相當於亞毫秒級的。當請求達到或超過該設置值后,其其余就會被拒絕。默認值是100。參考: Hystrix semaphore和thread隔離策略的區別及配置參考

這個參數本來直接可以通過Hystrix的命名規則來設置,但被zuul重新設計了,使得在zuul中semaphores的最大並發請求有4個方法的參數可以設置,如果4個參數都存在優先級(1~4)由高到低:

  • [優先級1]zuul.eureka.api.semaphore.maxSemaphores
  • [優先級2]zuul.semaphore.max-semaphores
  • [優先級3]hystrix.command.api.execution.isolation.semaphore.maxConcurrentRequests
  • [優先級4]hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests

需要注意的是:在Camden.SR3版本的zuul中hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests設置不會起作用,這是因為在org.springframework.cloud.netflix.zuul.filters.ZuulProperties.HystrixSemaphore.maxSemaphores=100設置了默認值100,因此zuul.semaphore.max-semaphores的優先級高於hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests

zuul.eureka.[commandKey].semaphore.maxSemaphores:
其中commandKey為

 

其他Hystrix參數:

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds用來設置thread和semaphore兩種隔離策略的超時時間,默認值是1000。

  • 建議設置這個參數,在Hystrix 1.4.0之前,semaphore-isolated隔離策略是不能超時的,從1.4.0開始semaphore-isolated也支持超時時間了。
  • 建議通過CommandKey設置不同微服務的超時時間,對於zuul而言,CommandKey就是service id:hystrix.command.[CommandKey].execution.isolation.thread.timeoutInMilliseconds

 

zuul 重試配置
  Spring Cloud Zuul模塊本身就包含了對於hystrix和ribbon的依賴,當我們使用zuul通過path和serviceId的組合來配置路由的時候,可以通過hystrix和ribbon的配置調整路由請求的各種時間超時機制。

 

  

1 ribbon配置舉例

  配置連接超時時間1秒,請求處理時間2秒,統一服務server嘗試重連1次,切換server重連1次

  

2 hystirx配置舉例

  

這里需要注意的是hystrix的配置時間應該大於ribbon全部重試時間的總和,上面我配置的是2次重試,包括首次請求,三次時間是6秒

 

3 打開zuul的重試配置:

  

特別注意zuul的重試配置需要依賴spring的retry,不然的話怎么配置都是徒勞

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM