springcloud微服务-hystrix
hystrix的作用:防止服务雪崩,隔离异常服务,提供降级方案
requestCache,在一个请求中有效。
降级步骤:
1.写一个降级类
2.通过hystrixcommand注解,指定降级方法,并且可以实现多级降级
熔断步骤:
1.熔断配置参数,在一定时间窗口内,请求数量达标,错误率达标,则开启熔断,经过一定时间,进入半开启状态,尝试发起请求,如果请求成功,则熔断器关闭,否则继续开启。

互联网项目主链路保卫战
关键词:钱和流量









线程隔离:
1.线程池,默认。性能比信号量差,但是能主动进行超时判定。
2.信号量,只建议在超高并发的非外部接口的调用上使用,直接使用tomcat的容器线程,没有新的资源开销。 execution.isolation.strategy = ExecutionIsolationStrategy.SEMAPHORE
yml文件配置hystrix降级
hystrix:
command:
#有的属性是默认配置,为了教学目的
default:
fallback:
enabled: true
circuitBreaker:
enabled: true
#超过50%错误开启熔断
errorThresholdPercentage: 50
#5个request之后才开始统计
requestVolumeThreshold: 5
#10秒之后进入半开状态
sleepWindowInMillisecond: 10000
execution:
timeout:
enabled: true
#可以指定线程隔离方式是线程池还是信号量
isolation:
thread:
interruptOnTimeout: true
interruptOnFutureCancle: true
timeoutInMilliseconds: 10000
metrics:
rollingStats:
#时间窗口统计
timeInMilliseconds: 20000
#计数桶,要能被时间窗口整除,用来均匀分布
numBuckets: 10
rollingPercentile:
#时间窗口统计
timeInMilliseconds: 20000
#计数桶,要能被时间窗口整除,用来均匀分布
numBuckets: 10
bucketSize: 300
#对特定配置属性的重载
loginFail:
execution:
isolation:
thread:
timeoutInMilliseconds: 3000
解决amigious mapping错误的方法:
1.@enableFeignClients注解,指定clients属性,把所有要加载的类罗列出来
2.原始feign接口不指定requestmapping
3.原始feign接口不指定feignClient
浙公网安备 33010602011771号