Sentinel降级—RT

1)RT:平均响应时间;配置平均响应时间为200ms,200ms内就要将请求处理完成;

2)注意:Sentinel 默认统计的 RT 上限是4900ms,超出此阈值会算作 4900ms ,若需要变更此上限可以通过启动配置项 -Dcsp.sentinel.statistic.max.rt=xxx 来配置;

3)按照下述图片配置:

永远一秒打进来10个线程(大于5个了)调用testD,我们希望200ms处理完本次任务,如果超过200ms还没有处理完,在未来1秒钟的时间窗口内,断路器打开(保险丝跳闸)微服务不可用,保险丝跳闸断电了;

 

RT-触发降级流程

1秒持续进入5个请求且平均响应时间大于阈值 ----> 触发降级(断路器打开)

----> 时间窗口结束 ----> 关闭降级

 降级策略—异常比例

异常比例:当资源的每秒请求量>=5,并且每秒异常总数占通过量的比值超过阈值之后,资源进入降级状态,即在接下来的时间窗口之内,对这个方法的调用都会自动返回。异常比例的阈值范围[0.0,0.1),代表 0% ~ 100%。

总结:QPS>=5 && 异常请求数 / 总请求数的比例> 异常比例,服务进行熔断降级;

熔断时间为配置的时间窗口2s

 @GetMapping("/testD")
 public String testD() {
        int a = 10 / 0;
        return "------testD";
 }

 降级策略—异常数

异常数:当资源近一分钟的异常数目超过阈值之后会进行熔断。注意由于统计时间窗口是分钟级别的,若 timeWindow 小于60s,则结束熔断状态仍可能再进入熔断状态。

注意:时间窗口一定要大于等于60s

异常数熔断流程:

异常数(分钟统计)超过阈值 ----> 触发降级(断路器打开)----> 时间窗口结束 ----> 关闭降级

http://localhost:8401/testD ,第一次访问绝对报错,因为除数不能为零,我们看到的是error窗口,但是达到5次报错后,进入熔断后降级。

 @GetMapping("/testD")
 public String testD() {
        int a = 10 / 0;
        return "------testD";
 }
GitHub 加速计划 / sentine / Sentinel
43
7
下载
alibaba/Sentinel: Sentinel 是阿里巴巴开源的一款面向分布式服务架构的流量控制、熔断降级组件,提供实时监控、限流、降级和系统保护功能,适用于微服务治理场景。
最近提交(Master分支:2 个月前 )
a08dc695 * Fix the bugs mentioned in issue #3562 and #3563. Fix the issue in the spring-webmvc-v6x-adapter where, after configuring http-method-specify:true, the prefixes for different request methods were not concatenated. Fix incorrect time unit in the tooltip when adding a new circuit breaker rule with statistical window duration. * Fix the bugs mentioned in issue #3562 and #3563. Fix the issue in the spring-webmvc-v6x-adapter where, after configuring http-method-specify:true, the prefixes for different request methods were not concatenated. Fix incorrect time unit in the tooltip when adding a new circuit breaker rule with statistical window duration. * Fixed the issue where the original test class was affected by the concatenation of resource names after adding the logic for the HTTP prefix concatenation. * remove mseHttpMethodSpecify field and update the unit test as suggested. * retrigger CI 19 天前
e60f0d0e * Simple rules should have higher priority than regular expression rules * Add optional switch to skip regex matching when simple rules already match, default: false, keeps backward compatibility. * fix RuleManagerTest unit test failure 19 天前
Logo

新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐