From 6799da270ddd7391ea12dd3f456824a2d6a1d9d5 Mon Sep 17 00:00:00 2001 From: Carpenter Lee Date: Mon, 3 Sep 2018 11:54:59 +0800 Subject: [PATCH] Fixed #109: fix miss-usage of ClusterNode.successQps() in DegradeRule.passCheck() method --- .../com/alibaba/csp/sentinel/node/Node.java | 33 ++++++++++++------- .../slots/block/degrade/DegradeRule.java | 5 +-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/Node.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/Node.java index 9c919b5d2a..427c45a7e4 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/Node.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/Node.java @@ -17,6 +17,7 @@ import java.util.Map; +import com.alibaba.csp.sentinel.Entry; import com.alibaba.csp.sentinel.node.metric.MetricNode; /** @@ -28,63 +29,68 @@ public interface Node { /** - * Incoming request per minute. + * Get incoming request per minute. {@code pass + blocked} */ long totalRequest(); + /** + * Get {@link Entry#exit()} count per minute. + * + * @return Outgoing request per minute. + */ long totalSuccess(); /** - * Blocked request count per minute. + * Get blocked request count per minute. */ long blockedRequest(); /** - * Exception count per minute. + * Get exception count per minute. */ long totalException(); /** - * Incoming request per second. + * Get pass request per second. */ long passQps(); /** - * Blocked request per second. + * Get blocked request per second. */ long blockedQps(); /** - * Incoming request + block request per second. + * Get {@link #passQps()} + {@link #blockedQps()} request per second. */ long totalQps(); /** - * Outgoing request per second. + * Get {@link Entry#exit()} request per second. */ long successQps(); long maxSuccessQps(); /** - * Exception count per second. + * Get exception count per second. */ long exceptionQps(); /** - * Average response per second. + * Get average rt per second. */ long avgRt(); long minRt(); /** - * Current active thread. + * Get current active thread count. */ int curThreadNum(); /** - * Last seconds block QPS. + * Get last second blocked QPS. */ long previousBlockQps(); @@ -97,6 +103,11 @@ public interface Node { void addPassRequest(); + /** + * Add rt and success count. + * + * @param rt + */ void rt(long rt); void increaseBlockedQps(); 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 1b50fb46a1..e1fc54874a 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 @@ -183,11 +183,12 @@ public boolean passCheck(Context context, DefaultNode node, int acquireCount, Ob return true; } - if (success == 0) { + double realSuccess = success - exception; + if (realSuccess <= 0) { return exception < RT_MAX_EXCEED_N; } - if (exception / (success + exception) < count) { + if (exception / success < count) { return true; } }