PART1
而我使用HystrixCommand进行服务,并使用jmeter进行高并发测试。测试结果太差了,请看flowing。代码->
@HystrixCommand(fallbackMethod = "helloFallback")
@RequestMapping(value="/hello", method=RequestMethod.GET)
@ResponseBody
public ResponseResult hello() throws Exception{
ResponseResult responseResult = new ResponseResult();
responseResult.setCode(200);
responseResult.setData("bank test ok");
return responseResult;
}
public ResponseResult helloFallback(){
ResponseResult responseResult = new ResponseResult();
responseResult.setCode(400);
responseResult.setData("timeout error");
return responseResult;
}测试重用:jmeter_test1
PART2
但是,如果我注释掉HystrixCommand,测试结果是完美的。comment >
// @HystrixCommand(fallbackMethod = "helloFallback")
@RequestMapping(value="/hello", method=RequestMethod.GET)
@ResponseBody
public ResponseResult hello() throws Exception{
ResponseResult responseResult = new ResponseResult();
responseResult.setCode(200);
responseResult.setData("bank test ok");
return responseResult;
}
public ResponseResult helloFallback(){
ResponseResult responseResult = new ResponseResult();
responseResult.setCode(400);
responseResult.setData("timeout error");
return responseResult;
}测试结果->jmeter_test2
小贴士:线程图片jmeter_test3
无论我使用zuul直接转发和调用服务,测试结果都是一样的。那么,是springcloud hystrix在高并发时的问题,还是我的代码有问题。欢迎任何回复!
发布于 2017-10-26 16:24:15
首先,请尝试调整以下属性。
hystrix.threadpool.default.coreSize默认的线程池大小只有10,对于您的性能测试来说,它的大小非常小。
在您使用hystrix的第一次测试中,您可以看到31%的错误率。这可能意味着可能会有许多线程池被拒绝,因为默认线程池只有10个。
如你所知,Hystrix通过断路器提供了很好的隔离,它需要一些成本来处理它。因此,一些性能降级是不可避免的。但是你的测试结果看起来不正常。
您可以找到有关hystrix配置here的更多详细信息
https://stackoverflow.com/questions/46923160
复制相似问题