Fork me on GitHub

Spring Cloud各组件调优参数

目录

Spring Cloud整合了各种组件,每个组件往往还有各种参数。本文来详细探讨Spring Cloud各组件的调优参数。欢迎联系我的QQ:511932633 或微信:jumping_me ,补充或者勘误,一起总结出最全、最实用的调优参数。

Tomcat配置参数

1
2
3
4
server:
tomcat:
max-connections: 0 # 默认值
max-threads: 0 # 默认值

Hystrix配置参数

  • 如隔离策略是THREAD:
1
2
3
hystrix.threadpool.default.coreSize: 10
hystrix.threadpool.default.maximumSize: 10
hystrix.threadpool.default.maxQueueSize: -1 # 如该值为-1,那么使用的是SynchronousQueue,否则使用的是LinkedBlockingQueue。注意,修改MQ的类型需要重启。例如从-1修改为100,需要重启,因为使用的Queue类型发生了变化

如果想对特定的HystrixThreadPoolKey 进行配置,则将default 改为 HystrixThreadPoolKey 即可。

  • 如果隔离策略是SEMAPHORE:
1
2
hystrix.command.default.execution.isolation.strategy: SEMAPHORE
hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests: 10 # 默认值

如果想对指定的HystrixCommandKey 进行配置,则将default 改为HystrixCommandKey 即可。

Feign配置参数

Feign默认没有线程池。

当使用HttpClient时,可如下设置:

1
2
3
4
5
feign:
httpclient:
enabled: true
max-connections: 200 # 默认值
max-connections-per-route: 50 # 默认值

代码详见:

  • org.springframework.cloud.netflix.feign.FeignAutoConfiguration.HttpClientFeignConfiguration#connectionManager
  • org.springframework.cloud.netflix.feign.ribbon.HttpClientFeignLoadBalancedConfiguration.HttpClientFeignConfiguration#connectionManager

当使用OKHttp时,可如下设置:

1
2
3
4
5
6
feign:
okhttp:
enabled: true
httpclient:
max-connections: 200 # 默认值
max-connections-per-route: 50 # 默认值

代码详见:

  • org.springframework.cloud.netflix.feign.FeignAutoConfiguration.OkHttpFeignConfiguration#httpClientConnectionPool
  • org.springframework.cloud.netflix.feign.ribbon.OkHttpFeignLoadBalancedConfiguration.OkHttpFeignConfiguration#httpClientConnectionPool

Zuul配置参数

我们知道Hystrix有隔离策略:THREAD 以及SEMAPHORE ,默认是 SEMAPHORE

隔离策略

1
2
zuul:
ribbon-isolation-strategy: thread

最大信号

当Zuul的隔离策略为SEMAPHORE时:

设置默认最大信号量:

1
2
3
zuul:
semaphore:
max-semaphores: 100 # 默认值

设置指定服务的最大信号量:

1
2
3
4
5
zuul:
eureka:
<commandKey>:
semaphore:
max-semaphores: 100 # 默认值

参考:

Zuul参数

  • Hystrix并发参数

Edgware及之后的版本中,当Zuul的隔离策略为THREAD时,可为Hystrix配置独立线程池:

参考:http://www.itmuch.com/spring-cloud/edgware-new-zuul-hystrix-thread-pool/

如果不设置独立线程池,那么HystrixThreadPoolKeyRibbonCommand

Hystrix并发配置参数请参考《Hystrix并发配置参数一节》

  • Zuul并发参数:

Zuul内置的Filterhttp://www.itmuch.com/%2Fspring-cloud%2Fzuul%2Fzuul-filter-in-spring-cloud%2F

对于形如:

1
2
3
4
5
zuul:
routes:
user-route: # 该配置方式中,user-route只是给路由一个名称,可以任意起名。
url: http://localhost:8000/ # 指定的url
path: /user/** # url对应的路径。

的路由,可使用如下方式配置并发参数:

1
2
3
4
zuul:
host:
max-total-connections: 200 # 默认值
max-per-route-connections: 20 # 默认值
  • 当Zuul底层使用的是Apache HttpClient时,对于使用Ribbon的路由,可使用如下方式配置并发参数:
1
2
3
4
serviceId:
ribbon:
MaxTotalConnections: 0 # 默认值
MaxConnectionsPerHost: 0 # 默认值

相关代码:org.springframework.cloud.netflix.ribbon.support.AbstractLoadBalancingClient 子类的createDelegate 方法。

相关文章

评论系统未开启,无法评论!