zuul网关配置请求并发以及重试

介绍

Zuul默认集成hystrix, 同时,和hystrix一样采用线程隔离技术
zuul默认使用:信号量(semaphore)
hystrix默认使用:线程池 (thread)

配置信号量

属性 描述
zuul.ribbon-isolation-strategy semaphore 配置隔离策略为信号量
zuul.semaphore.max-semaphores 1000 配置信号量大小
hystrix.command.default.execution.isolation.strategy semaphore 配置断路器中的隔离策略为信号量
hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests 1000 配置断路器中的信号量大小

没有测试过,只配置zuul是否生效, 或者2个配置不同,哪一个配置生效

重试

1.5.6
使用Ribbon zuul hystrix

引入重试jar包

<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
  
  
  • 1
  • 2
  • 3
  • 4

参考 LoadBalancerAutoConfiguration 以及RibbonAutoConfiguration
实现原理: RetryLoadBalancerInterceptor 实现 ClientHttpRequestInterceptor 通过拦截器实现

配置

属性 描述 默认值
spring.cloud.loadbalancer.retry.enabled ture 开启重试机制 true
zuul.retryable true 如果使用zuul,需要配置该属性 false
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds 8000 如果使用ribbon和hystrix,设置超时时间 1000
ribbon.OkToRetryOnAllOperations true 是否所有的操作都重试 false
ribbon.MaxAutoRetriesNextServer 2 重试负载均衡其他实例的最大重试次数,不包括首次实例 0
ribbon.MaxAutoRetries 0 同一台实例的最大重试次数,不包括首次调用 0
ribbon.ConnectTimeout 1000 http建立socket超时时间
ribbon.ReadTimeout 3000 http读取响应socket超时时间

注意:
- ribbon.ConnectTimeout+ribbon.ReadTimeout<hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds
- 连接失败的意思是服务宕机,请求不可到达, 并不是服务报错

猜你喜欢

转载自blog.csdn.net/didi7696/article/details/83304286
今日推荐