发生场景
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 {
}