Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cluster token checker #3407

Open
wants to merge 1 commit into
base: 1.8
Choose a base branch
from

Conversation

leeyazhou
Copy link

@leeyazhou leeyazhou commented May 29, 2024

  1. ClusterFlowChecker.acquireClusterToken
  2. ClusterParamFlowChecker.acquireClusterToken

Describe what this PR does / why we need it

集群限流情况下, windowIntervalMs大于1000ms时, 会出现限流不准确的情况.

测试场景:

FlowRule{count =2, clusterMode=true, clusterConfig { windowIntervalMs: 3000}}

        double latestAvg = metric.getAvg(ClusterFlowEvent.PASS);
        double globalThreshold = calcGlobalThreshold(rule) * ClusterServerConfigManager.getExceedCount();
        double nextRemaining = globalThreshold - latestAvg - acquireCount;

        if (nextRemaining >= 0) {
            return new TokenResult(TokenResultStatus.OK)
                .setRemaining((int) nextRemaining)
                .setWaitInMs(0);
        }

代码执行过程:

  1. 10:00:01.100, latestAvg=0, nextRemaining (1) >=0 通过
  2. 10:00:01.200, latestAvg=0.333, nextRemaining (0.66) >=0 通过
  3. 10:00:01.300, latestAvg=0.666, nextRemaining (0.33) >=0 通过
  4. 10:00:01.400, latestAvg=1, nextRemaining (0) >=0 通过

限流规则本来是3s通过2个, 现在已经通过了4个, 说明这个限流规则不准确

Does this pull request fix one issue?

Describe how you did it

ClusterFlowChecker.acquireClusterToken, 获取时间窗口内已通过的请求数时取总数, 而不是取QPS

        double latestSum = metric.getSum(ClusterFlowEvent.PASS);
        double globalThreshold = calcGlobalThreshold(rule) * ClusterServerConfigManager.getExceedCount();
        double nextRemaining = globalThreshold - latestSum - acquireCount;

        if (nextRemaining >= 0) {
            return new TokenResult(TokenResultStatus.OK)
                .setRemaining((int) nextRemaining)
                .setWaitInMs(0);
        }

Describe how to verify it

Special notes for reviews

1. ClusterFlowChecker.acquireClusterToken
2. ClusterParamFlowChecker.acquireClusterToken
@CLAassistant
Copy link

CLAassistant commented May 29, 2024

CLA assistant check
All committers have signed the CLA.

@leeyazhou leeyazhou closed this May 29, 2024
@leeyazhou leeyazhou reopened this May 29, 2024
@LearningGp LearningGp added to-review To review area/cluster-flow Issues or PRs related to cluster flow control labels May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cluster-flow Issues or PRs related to cluster flow control to-review To review
3 participants