原文:<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配置参数
  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 即可。
  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参数
  Edgware及之后的版本中,当Zuul的隔离策略为THREAD时,可为Hystrix配置独立线程池:
 参考:<http://www.itmuch.com/spring-cloud/edgware-new-zuul-hystrix-thread-pool/>
 如果不设置独立线程池,那么HystrixThreadPoolKey 是 RibbonCommand 。
 Hystrix并发配置参数请参考《Hystrix并发配置参数一节》
  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 方法。