Spring Cloud 各组件调优参数

Spring Cloud整合了各种组件,每个组件往往还有各种参数。本文来详细探讨Spring Cloud各组件的调优参数。

Tomcat配置参数

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

Hystrix配置参数

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

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

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

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

Feign配置参数

Feign默认没有线程池。

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

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

代码详见:

  • org.springframework.cloud.netflix.feign.FeignAutoConfiguration.

    HttpClientFeignConfiguration#connectionManager

  • org.springframework.cloud.netflix.feign.ribbon.

    HttpClientFeignLoadBalancedConfiguration.HttpClientFeignConfiguration#connectionManager

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

  1 feign:
  2   okhttp:
  3     enabled: true
  4   httpclient:
  5     max-connections: 200 # 默认值
  6     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 zuul:
  2   ribbon-isolation-strategy: thread
最大信号

当Zuul的隔离策略为SEMAPHORE时:

设置默认最大信号量:

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

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

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

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

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

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



转载自:http://www.itmuch.com/spring-cloud-sum/spring-cloud-concurrent/

posted @ 2017-12-12 16:17  长情白月光  阅读(6905)  评论(0编辑  收藏  举报