背景
我们的项目用的是微服务架构,JDK版本JDK12,springboot的版本是2.1.6,springcloud的版本是Greenwich,服务之间通过feign调用.今天在给项目做压测,发现很多请求都过不了,后来排查原因,
发现是模块之间调用时发生了Hystrix调用异常。
然后就去网上查找解决方案,发现需要修改springcloud Hystix的配置。
修改前的配置
hystrix:
command:
default:
execution:
timeout:
enabled: true
isolation:
thread:
timeoutInMilliseconds: 5000
修改后的配置
我们的配置基本是用的默认的,需要设置线程池的属性,直接上配置:
hystrix:
threadpool:
default:
coreSize: 200 ##并发执行的最大线程数,默认10
maxQueueSize: 200 ##BlockingQueue的最大队列数
queueSizeRejectionThreshold: 50
##即使maxQueueSize没有达到,达到queueSizeRejectionThreshold该值后,请求也会被拒绝
execution:
timeout:
enabled: true
isolation:
strategy: THREAD
semaphore:
maxConcurrentRequests: 1000
thread:
timeoutInMilliseconds: 30000
command:
default:
execution:
timeout:
enabled: true
isolation:
thread:
timeoutInMilliseconds: 5000
改完之后再测,神奇的发现果然没有问题啦。
既然遇到了Hystrix,那么就来看一看springcloud的Hystrix都有哪些配置吧
Hystrix配置属性详解
- Execution:控制HystrixCommand.run() 的如何执行
- Execution:控制HystrixCommand.run() 的如何执行
- Circuit Breaker: 控制断路器的行为
- Metrics: 捕获和HystrixCommand 和 HystrixObservableCommand 执行信息相关的配置属性
- Request Context:设置请求上下文的属性
- Collapser Properties:设置请求合并的属性
- Thread Pool Properties:设置线程池的属性