Fix QPS mode of system rule: use passQps instead of successQps and support batchCount (#2455)

This commit is contained in:
wucheng1997 2021-11-23 10:16:47 +08:00 committed by GitHub
parent d4ea89e978
commit 3e9f42efce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View File

@ -287,7 +287,7 @@ public final class SystemRuleManager {
* @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 final class SystemRuleManager {
}
// 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");
}

View File

@ -35,7 +35,7 @@ public class SystemSlot extends AbstractLinkedProcessorSlot<DefaultNode> {
@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);
}

View File

@ -92,7 +92,8 @@ public class SystemRuleManagerTest {
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;
}