适用版本:
spring-boot: 1.4.x.RELEASE
spring-cloud:Camden.SR3
Hystrix: 1.5.6
spring-boot-tomcat 优化参数:
主要只有2个,最大和最小worker线程:
server.tomcat.max-threads=128 # Maximum amount of worker threads.
server.tomcat.min-spare-threads=64 # Minimum amount of worker threads.
spring-boot-undertow 优化参数:
ioThreads
设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接,默认取CPU核心数量,最小值为2。
Math.max(Runtime.getRuntime().availableProcessors(), 2);
spring-boot 参数: server.undertow.io-threads=
worker-threads
阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载,默认值为io-threads*8。
spring-boot 参数: server.undertow.worker-threads=
buffer
buffer-size:
每块buffer的空间大小,越小的空间被利用越充分。
buffers-per-region:
每个区分配的buffer数量 , 所以pool的大小是buffer-size * buffers-per-region。
directBuffers
是否分配的直接内存。
获取JVM最大可用内存 maxMemory=Runtime.getRuntime().maxMemory();
maxMemory<64M,不开启directBuffers, bufferSize = 512,buffersPerRegion = 10;
64<=maxMemory<128M,开启directBuffers, bufferSize = 1024 bytes,buffersPerRegion = 10;
maxMemory>128M,开启directBuffers, bufferSize = 16*1024 bytes,buffersPerRegion = 20;
spring-boot 参数:
# 最大可用内存<64M,不开启
server.undertow.buffer-size= # Size of each buffer in bytes.
server.undertow.buffers-per-region= # Number of buffer per region.
server.undertow.direct-buffers= # Allocate buffers outside the Java heap.
//默认值:cpu数量,最小为2
server.undertow.io-threads= # Number of I/O threads to create for the worker.
//默认值:io-threads*8
server.undertow.worker-threads= # Number of worker threads.
zuul 内置参数
zuul.host.maxTotalConnections
适用于ApacheHttpClient,如果是okhttp无效。每个服务的http客户端连接池最大连接,默认是200.
zuul.host.maxPerRouteConnections
适用于ApacheHttpClient,如果是okhttp无效。每个route可用的最大连接数,默认值是20。
zuul.semaphore.max-semaphores
Hystrix最大的并发请求 execution.isolation.semaphore.maxConcurrentRequests
,这个值并非 TPS
、 QPS
、 RPS
等都是相对值,指的是1秒时间窗口内的事务/查询/请求, semaphore.maxConcurrentRequests
是一个绝对值,无时间窗口,相当于亚毫秒级的。当请求达到或超过该设置值后,其其余就会被拒绝。默认值是100。参考: Hystrix semaphore和thread隔离策略的区别及配置参考
这个参数本来直接可以通过Hystrix的命名规则来设置,但被zuul重新设计了,使得在zuul中semaphores的最大并发请求有4个方法的参数可以设置,如果4个参数都存在优先级(1~4)由高到低:
- [优先级1]zuul.eureka.api.semaphore.maxSemaphores
- [优先级2]zuul.semaphore.max-semaphores
- [优先级3]hystrix.command.api.execution.isolation.semaphore.maxConcurrentRequests
- [优先级4]hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests
需要注意的是:在Camden.SR3版本的zuul中 hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests
设置不会起作用,这是因为在 org.springframework.cloud.netflix.zuul.filters.ZuulProperties.HystrixSemaphore.maxSemaphores=100
设置了默认值100,因此 zuul.semaphore.max-semaphores
的优先级高于 hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests
。
zuul.eureka.[commandKey].semaphore.maxSemaphores:
其中commandKey为
参考设置参数:
#
zuul.host.maxTotalConnections: 200
zuul.host.maxPerRouteConnections: 10
#zuul.semaphore.max-semaphores: 128
# 建议使用这种方式来设置,可以给每个不同的后端微服务设置不同的信号量
zuul.eureka.[service id].semaphore.maxSemaphores: 128
其他Hystrix参数:
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds
用来设置thread和semaphore两种隔离策略的超时时间,默认值是1000。
- 建议设置这个参数,在Hystrix 1.4.0之前,semaphore-isolated隔离策略是不能超时的,从1.4.0开始semaphore-isolated也支持超时时间了。
- 建议通过CommandKey设置不同微服务的超时时间,对于zuul而言,CommandKey就是service id:
hystrix.command.[CommandKey].execution.isolation.thread.timeoutInMilliseconds
ribbon参数
ribbon:
# # Max number of next servers to retry (excluding the first server)
# MaxAutoRetries: 1
# # Whether all operations can be retried for this client
# MaxAutoRetriesNextServer: 1
# # Interval to refresh the server list from the source
# OkToRetryOnAllOperations: true
# # Interval to refresh the server list from the source
# ServerListRefreshInterval: 2000
# # Connect timeout used by Apache HttpClient
ConnectTimeout: 3000
# # Read timeout used by Apache HttpClient
ReadTimeout: 3000
主要是 ConnectTimeout
和 ReadTimeout
2个参数,最终会设置到http Client中。
http://www.tuicool.com/articles/aMRnIfr
相关推荐
主要介绍了springcloud 中 zuul 修改请求参数信息的方法,需要的朋友可以参考下
spring-cloud-netflix-zuul-websocket, Zuul反向代理网络套接字支持 spring-cloud-netflix-zuul-websocketspring 应用程序中支持Zuul反向代理web套接字支持的简单库。用法spring-cloud-netflix-zuul-websocket可以从...
zuul 企业级应用
spring cloud框架下的单点登录sso技术 oauth2实现的认证 授权 以及zuul作为网关路由 可以参考学习使用
SpringBoot + Zuul + ribbon 中实现负载均衡
spring-cloud-zuul(包含注册中心、服务生产者、服务消费者、zuul网关路由).zip 暂时只有zuul反向代理
spring boot、zuul整合的微服务网关配置代码demo,供学习参考
zuul-2.1\zuul-sample\src\main\java\com\netflix\zuul\sample 下 Bootstrap中的main方法可运行 官网源码基础上修改
Zuul 是提供动态路由,监控,弹性,安全等的边缘服务。Zuul 相当于是设备和 Netflix 流应用的 Web...Zuul 包含多个组件:zuul-core zuul-simple-webapp zuul-netflix zuul-netflix-webapp 标签:Zuul Web框架
Zuul的规则引擎允许通过任何JVM语言来编写规则和过滤器, 支持基于Java和Groovy的构建。(spring cloud zuul整合例子包能运行)
zuul oauth2
spring cloud 客户端和spring cloud zuul ,和前面的两个是一个系列,先打开cloud service 的服务,然后打开 product ,在打开客户端,最后可以打开zuul 可以实现eurake的负载均衡,zuul的负载均衡。
spring cloud eureka zuul ribbon hystrix feign config 示例代码
SpringCloud zuul 组件的jar包,可以用作联调SpringCloud测试使用。
Spring Cloud Zuul示例, 支持服务自动发现,注册中心为Consul
zuul网关源码,非常优秀的网关设计,源码设计也非常友好
Zuul的前世今生.pptx
在本例中,我们将介绍如何通过Zuul和Eureka一起使用来实现负载均衡。 我们将请求路由到注册在Spring Cloud Eureka,并通过Zuul Proxy来发现的REST服务。
springcloud zuul gateway 服务网关 http://knight-black-bob.iteye.com/blog/2357683
演示了如何在一个Spring Cloud架构中使用zuul网关,实现动态路由,详细解释了zuul的各种配置