Feign Hystrix Tomcat參數配置


Feign配置參數

Feign默認情況下不使用線程池,feign通過jdk中的HttpURLConnection向下游服務發起http請求。若想使用HttpClient時,可這樣設置:
feign.httpclient.enabled=true
feign.httpclient.max-connections=200 # #連接池中最大連接數,默認值200
feign.httpclient.max-connections-per-route=50 # 每個route最大並發連接數 默認值50

#route就是一條路由,它將一個URL路徑和一個函數進行映射
#在這里我們可以分別將max-connections-per-route值設置為1和2進行測試
#設置為1時,請求是串行進行的,第一個請求處理完並返回之后,才會再發起第二個請求。
#設置為2時,請求時並行進行的,第一個請求處理過程中還沒返回,第二個請求同時可以發起。
#最后,注意:該值必須比hystrix.threadpool.default.maximumSize小才有意義,因為其已經在前攔截一層。

默認配置在以下類中:
org.springframework.cloud.netflix.feign.ribbon.HttpClientFeignLoadBalancedConfiguration.HttpClientFeignConfiguration#connectionManager
org.springframework.cloud.netflix.feign.FeignAutoConfiguration.HttpClientFeignConfiguration#connectionManager

工程啟動時會看到如下日志,代表feign httpclient連接池生效。

2019-07-04 19:23:47.574 [http-nio-8001-exec-191] DEBUG o.a.h.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://162.16.2.69:8021][to
tal kept alive: 0; route allocated: 50 of 50; total allocated: 50 of 200]

 

Hystrix配置參數

ThreadPool 線程池配置
hystrix.threadpool.default.coreSize=200      #並發執行的核心線程數,默認10。不能設置為0,初始化setter的時候會出現異常。設置服務端容器線程差不多,吞吐量較高
hystrix.threadpool.default.maximumSize=300   #並發執行的最大線程數,默認10。
hystrix.threadpool.default.maxQueueSize=400  #BlockingQueue的最大隊列數,當設為-1,會使用SynchronousQueue,值為正時使用LinkedBlcokingQueue。
hystrix.threadpool.default.queueSizeRejectionThreshold=500 #隊列截斷閾值,即使maxQueueSize沒有達到,達到queueSizeRejectionThreshold后,請求也會被拒絕。若maxQueueSize=-1,該字段將不起作用。

 

hystrix.threadpool.default.keepAliveTimeMinutes 線程空閑存活時間。如果corePoolSize和maxPoolSize設成一樣(默認實現)該設置無效。
hystrix.threadpool.default.metrics.rollingStats.timeInMilliseconds 線程池統計指標的時間,默認10000。
hystrix.threadpool.default.metrics.rollingStats.numBuckets 將rolling window划分為n個buckets,默認10。

建議設置值: 
timeoutInMilliseconds:依賴外部接口時,推薦配置比rpc超時時間稍短,否則可能無法發揮作用。 
maxConcurrentRequests:估算值:(單機QPS*響應時間)*2/1000,2為預留一倍值,可以自行調整。 
coreSize:估算值:(單機qps*響應時間)*1.5/1000,1.5為預留0.5倍buffer,該值可以適當減少,因為線程池會有排隊隊列。 
maxQueueSize:僅在allowMaximumSizeToDivergeFromCoreSize(是否開啟動態線程數)為true時才生效。建議設置core的兩倍大小。

Hystrix參數優先級大於feign httpclient的參數優先級,也就是說Hystrix線程池控制是在feign httpclient連接池控制的前一層。

Tomcat配置參數

server.tomcat.uri-encoding=UTF-8
server.tomcat.max-connections=20000  # Maximum number of connections that the server accepts and processes at any given time. server.tomcat.max-threads=1000      # Maximum number of worker threads. server.tomcat.max-http-header-size=0 # Maximum size, in bytes, of the HTTP message header. server.tomcat.max-http-post-size=0 # Maximum size, in bytes, of the HTTP post content. server.tomcat.min-spare-threads=0 # Minimum number of worker threads.

 

參考:

Zuul官方 https://github.com/Netflix/zuul/wiki/How-it-Works

Hystrix官方 https://github.com/Netflix/Hystrix/wiki 

https://github.com/Netflix/Hystrix/wiki/Configuration#coreSize

https://blog.csdn.net/u013889359/article/details/80118884 

https://blog.csdn.net/wd2014610/article/details/82182617 

https://www.cnblogs.com/seifon/p/9921774.html

https://yq.aliyun.com/articles/622348


免責聲明!

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



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