diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java index d860344e2f..4ee5f17ccf 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java @@ -287,7 +287,7 @@ public static void loadSystemConf(SystemRule rule) { * @param resourceWrapper the resource. * @throws BlockException when any system rule's threshold is exceeded. */ - public static void checkSystem(ResourceWrapper resourceWrapper) throws BlockException { + public static void checkSystem(ResourceWrapper resourceWrapper, int count) throws BlockException { if (resourceWrapper == null) { return; } @@ -302,8 +302,8 @@ public static void checkSystem(ResourceWrapper resourceWrapper) throws BlockExce } // total qps - double currentQps = Constants.ENTRY_NODE == null ? 0.0 : Constants.ENTRY_NODE.successQps(); - if (currentQps > qps) { + double currentQps = Constants.ENTRY_NODE == null ? 0.0 : Constants.ENTRY_NODE.passQps(); + if (currentQps + count > qps) { throw new SystemBlockException(resourceWrapper.getName(), "qps"); } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemSlot.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemSlot.java index c98e491c47..44b5472703 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemSlot.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemSlot.java @@ -35,7 +35,7 @@ public class SystemSlot extends AbstractLinkedProcessorSlot { @Override public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count, boolean prioritized, Object... args) throws Throwable { - SystemRuleManager.checkSystem(resourceWrapper); + SystemRuleManager.checkSystem(resourceWrapper, count); fireEntry(context, resourceWrapper, node, count, prioritized, args); } diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManagerTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManagerTest.java index fcd1f66512..2e7ac3a3e2 100644 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManagerTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManagerTest.java @@ -92,7 +92,8 @@ public void testCheckMaxCpuUsageNotBBR() throws Exception { boolean blocked = false; try { - SystemRuleManager.checkSystem(new StringResourceWrapper("testCheckMaxCpuUsageNotBBR", EntryType.IN)); + StringResourceWrapper resourceWrapper = new StringResourceWrapper("testCheckMaxCpuUsageNotBBR", EntryType.IN); + SystemRuleManager.checkSystem(resourceWrapper, 1); } catch (BlockException ex) { blocked = true; }