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

posted @ 2019-05-22 17:29  killerqi  阅读(2324)  评论(0编辑  收藏  举报