Skip to content

Commit

Permalink
Fix QPS mode of system rule: use passQps instead of successQps and su…
Browse files Browse the repository at this point in the history
…pport batchCount (alibaba#2455)
  • Loading branch information
wucheng1997 committed Nov 23, 2021
1 parent 518e652 commit da2c73d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit da2c73d

Please sign in to comment.