Spring Cloud各组件调优参数


声明:本文转载自https://my.oschina.net/eacdy/blog/1588275,转载目的在于传递更多信息,仅供学习交流之用。如有侵权行为,请联系我,我会及时删除。

原文:<http://www.itmuch.com/spring-cloud-sum/spring-cloud-concurrent/>

采用 CC BY 3.0 CN 许可协议。可自由转载、引用,但需署名作者且注明文章原文地址。

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

Tomcat配置参数

server:   tomcat:     max-connections: 0     max-threads: 0 

<!-- more -->

Hystrix配置参数

  • 如隔离策略是THREAD:
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:
hystrix.command.default.execution.isolation.strategy: SEMAPHORE hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests: 10 # 默认值 

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

Feign配置参数

Feign默认没有线程池。

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

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时,可如下设置:

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

隔离策略

zuul:   ribbon-isolation-strategy: thread 

最大信号

当Zuul的隔离策略为SEMAPHORE时:

设置默认最大信号量:

zuul:   semaphore:     max-semaphores: 100 # 默认值 

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

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内置的Filter<http://www.itmuch.com/%2Fspring-cloud%2Fzuul%2Fzuul-filter-in-spring-cloud%2F>

对于形如:

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

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

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

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

本文发表于2017年12月12日 12:33
(c)注:本文转载自https://my.oschina.net/eacdy/blog/1588275,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如有侵权行为,请联系我们,我们会及时删除.

阅读 2637 讨论 0 喜欢 0

抢先体验

扫码体验
趣味小程序
文字表情生成器

闪念胶囊

你要过得好哇,这样我才能恨你啊,你要是过得不好,我都不知道该恨你还是拥抱你啊。

直抵黄龙府,与诸君痛饮尔。

那时陪伴我的人啊,你们如今在何方。

不出意外的话,我们再也不会见了,祝你前程似锦。

这世界真好,吃野东西也要留出这条命来看看

快捷链接
网站地图
提交友链
Copyright © 2016 - 2021 Cion.
All Rights Reserved.
京ICP备2021004668号-1