From f144a2713fbb5ddf0ec3682eeb10fb6cc50dd5f0 Mon Sep 17 00:00:00 2001 From: Carpenter Lee Date: Wed, 1 Aug 2018 17:48:53 +0800 Subject: [PATCH] Refine Degrade rule checking. --- .../slots/block/degrade/DegradeRule.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java index 44f51c4f..1b50fb46 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java @@ -100,7 +100,7 @@ public class DegradeRule extends AbstractRule { return cut; } - public void setCut(boolean cut) { + private void setCut(boolean cut) { this.cut = cut; } @@ -108,10 +108,6 @@ public class DegradeRule extends AbstractRule { return passCount; } - public void setPassCount(AtomicLong passCount) { - this.passCount = passCount; - } - public int getTimeWindow() { return timeWindow; } @@ -143,12 +139,6 @@ public class DegradeRule extends AbstractRule { if (grade != that.grade) { return false; } - // if (cut != that.cut) { return false; } - //// AtomicLong dose not Override equals() - // if ((passCount == null && that.passCount != null) - // || (passCount.get() != that.passCount.get())) { - // return false; - // } return true; } @@ -158,9 +148,6 @@ public class DegradeRule extends AbstractRule { result = 31 * result + new Double(count).hashCode(); result = 31 * result + timeWindow; result = 31 * result + grade; - // result = 31 * result + (cut ? 1 : 0); - // result = 31 * result + (passCount != null ? (int)passCount.get() : - // 0); return result; } @@ -179,6 +166,7 @@ public class DegradeRule extends AbstractRule { if (grade == RuleConstant.DEGRADE_GRADE_RT) { double rt = clusterNode.avgRt(); if (rt < this.count) { + passCount.set(0); return true; } @@ -189,11 +177,17 @@ public class DegradeRule extends AbstractRule { } else { double exception = clusterNode.exceptionQps(); double success = clusterNode.successQps(); - if (success == 0) { + long total = clusterNode.totalQps(); + // if total qps less than RT_MAX_EXCEED_N, pass. + if (total < RT_MAX_EXCEED_N) { return true; } - if (exception / success < count) { + if (success == 0) { + return exception < RT_MAX_EXCEED_N; + } + + if (exception / (success + exception) < count) { return true; } }