# 发生场景
1、用户登陆压测场景 1,设置用户数 10 进行并发操作:压力都可正常登陆成功无异常情况
2、用户登陆压测场景 2,设置用户数 20 进行并发操作:压力测试过程出现错误率 5% 异常错误,根据异常情况去后端查看日志
3、核查发现有个服务异常 hhh-auth 异常日志内容提示连接池设置少,日志如下,核查数据库连接的配置文件,未发现设置 10 的最大连接数,跟线程数。
# 解决方案
我能解决这个问题是来源于某个大佬的这篇文章 Spring Cloud Hystrix 线程池队列配置 。
feign.hystrix.enabled=true | |
#并发执行的最大线程数,默认10 | |
hystrix.threadpool.default.coreSize=50 | |
#BlockingQueue的最大队列数,默认值-1 | |
hystrix.threadpool.default.maxQueueSize=1500 | |
#即使maxQueueSize没有达到,达到queueSizeRejectionThreshold该值后,请求也会被拒绝,默认值5 | |
hystrix.threadpool.default.queueSizeRejectionThreshold=1000 |
注意:如果要调整队列,必须同时修改 maxQueueSize 和 queueSizeRejectionThreshold 属性的值,否则都会出现异常!因为 queueSizeRejectionThreshold 官方的默认值只有 5。
附:报服务调用异常说明使用的是分布式系统,如果没有引用 Hystrix 包的话,首先请引用 Hystrix 包
<dependency> | |
<groupId>org.springframework.cloud</groupId> | |
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.cloud</groupId> | |
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> | |
</dependency> |
在启动类上加入注解 @EnableHystrixDashboard
@EnableDiscoveryClient | |
@EnableFeignClients | |
@SpringBootApplication | |
@EnableHystrixDashboard | |
public class HhhAuthApplication { | |
} |