某个报表 hystrix 超时异常 如下
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 10000
threadpool:
default:
coreSize: 20 #核心线程数
maximumSize: 200 #最大线程数
allowMaximumSizeToDivergeFromCoreSize: true #线程空闲时可以减少最大线程数
maxQueueSize: 1000 #最大请求等待队列
queueSizeRejectionThreshold: 1000 #最大拒绝队列阈值
这个配置 只是做了全局的超时配置 ,其实这一块是可以优化的 ,当然这一块可能还有其他的问题 , hystrix.command.default.circuitBreaker.enabled 默认为true的 10s 之类出现20个请求失败或者 错误比率阀值>50 是会发生熔断的 , 熔断后 默认5s 是拒绝请求的 (这里有个问题 是拒绝所有请求?怎么恢复呢) 。
如果不需要熔断 ,你直接可以 hystrix.command.default.circuitBreaker.enabled=false
如果需要熔断的话 ,需要对
hystrix.command.default.circuitBreaker.requestVolumeThreshold
hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds
hystrix.command.default.circuitBreaker.errorThresholdPercentage
做设置 。这里有个问题(请求失败的具体含义是什么)
熔断后 其实有个 half-open 状态 ,现在hystrix 只支持 single request测试 是否成功 。如果 这个request 失败继续熔断。成功则恢复
为什么不能对指定模块做超时设置呢 ,如何设置呢 。其实 可以的 。或者大家愿意看下git 开发文档的话 应该会更加容易理解
不同command 可以使用不同的策略 ,不同command 之间可以使用 不同的线程池
比如
hystrix.command.default 其实 是可以对应的是 hystrix.command.commandkey
commandkey 用于定义command
hystrix.threadpool.default其实 是可以对应的是 hystrix.command.threadpoolkey
如下
@HystrixCommand(groupKey = "fallback",
commandKey = "fallback", threadpoolkey=“fallback”
fallbackMethod = "hystrixFallBack")
大家看到这一点应该是明白了 。 默认threadpoolkey 不写 ,为 groupKey 。
下图为压测测试日志
3s timeout limit
sleep
null
fallback
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep end
3s timeout limit
sleep
null
fallback
null
null
fallback
null
fallback
null
fallback
fallback
null
null
fallback
null
fallback
null
fallback
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
3s timeout limit
3s timeout limit
3s timeout limit
sleep end
sleep end
sleep end
3s timeout limit
sleep end
3s timeout limit
3s timeout limit
sleep end
3s timeout limit
sleep end
sleep end
sleep end
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
3s timeout limit
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep
sleep end
3s timeout limit
sleep
null
null
null
fallback
null
fallback
null
fallback
fallback
fallback
null
fallback
null
fallback
null
fallback
null
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
null
fallback
fallback
Hystrix circuit short-circuited and is OPEN
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
Hystrix circuit short-circuited and is OPEN
fallback
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
Hystrix circuit short-circuited and is OPEN
fallback
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
sleep end
10s 之前的请求都是 3s timeout limit -> sleep->null ->failback -> sleep end 其实的话 ,就是接口超时 failback 过程 ,10s 后出现了fallback -> Hystrix circuit short-circuited and is OPEN 熔断就开始了 ,这个时候 所有请求 其实就不走 业务方法 直接到failback 方法了 。上图看不见恢复流程
hystrix 对于异常处理 除了 HystrixBadRequestException 以外的其他异常都会作为熔断计数统计 。这里有个疑问 ,对于使用 @HystrixCommand 注解的方法 ,非远程调用 ,爆出异常是否也会触发熔断机制呢 ,答案是 ,如下图 ,抛出空异常 ,会导致熔断 fallback。
@HystrixCommand(groupKey = "test",
commandKey = "test",
fallbackMethod = "hystrixFallBack")
@GetMapping(value = "/testException")
public List<Users> general1() {
Integer i = null ;
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
int b = i.intValue();
return new ArrayList<>();
}
然后 没有 @HystrixCommand 注解的方法 肯定不会触发fallback 方法 但是否会熔断呢 测试是 好像不会 。
最好一个问题 熔断的范围 ,不同commandkey ,不同threadpool key 下 不会相互影响 ,
不同commandkey , 相同 threadpool key 下 会受到影响? 超时策略 和 熔断策略 这块不同 ,不会影响 , 线程池策略这块 可能 会有影响 ,大家有空测下吧 。
想要测试代码可以留言找我
hystrix 请求合并 感觉 公司应该是用不到的 。
hystrix 请求缓存 感觉很鸡肋
网友评论