alibaba / alibaba/Sentinel

关于关联限流不精准的问题?

Open
#2,715 0 comments 0 reactions 0 assignees View on GitHub
kind/question
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

测试下来,这个关联限流好像非常的不精准。
直接上代码
``` java
List rules = new ArrayList();
FlowRule flowRule = new FlowRule();
flowRule.setResource(FLOW_KEY); //资源名,即限流规则的作用对象
flowRule.setCount(10); //限流阈值
flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); //限流阈值类型(QPS 或并发线程数)
flowRule.setLimitApp("default");
rules.add(flowRule);

FlowRule taskRule = new FlowRule();
taskRule.setResource(TASK_KEY); //资源名,即限流规则的作用对象
taskRule.setCount(10); //限流阈值
taskRule.setStrategy(RuleConstant.STRATEGY_RELATE);
taskRule.setGrade(RuleConstant.FLOW_GRADE_QPS); //限流阈值类型(QPS 或并发线程数)
taskRule.setRefResource(FLOW_KEY); //关联限流,如果FLOW_KEY达到20,那么这个将会被限流
taskRule.setLimitApp("default"); //流控针对的调用来源,若为 default 则不区分调用来源
rules.add(taskRule);
FlowRuleManager.loadRules(rules);
```
case 1:
如果限流阈值不够高,比如10,20这种,而且设置的一样的话,比如我期望FLOW_KEY 达到阈值之后就限流,这个基本无法生效。
```
flowRule.setCount(10);
taskRule.setCount(10);
```
result:
```
[flow_key]1652157865686, total:5774, pass:12, block:5762
[task_key]58 send qps is: 5697
[task_key]1652157866690, total:5697, pass:9, block:5688
[flow_key]58 send qps is: 5704
[flow_key]1652157866690, total:5704, pass:10, block:5694
[flow_key]56 send qps is: 5782
[flow_key]1652157867694, total:5782, pass:10, block:5773
[task_key]56 send qps is: 5800
[task_key]1652157867694, total:5800, pass:13, block:5787
[task_key]54 send qps is: 5713
[flow_key]54 send qps is: 5714
[task_key]1652157868699, total:5713, pass:16, block:5697
[flow_key]1652157868699, total:5714, pass:10, block:5703
[flow_key]52 send qps is: 5686
[flow_key]1652157869703, total:5686, pass:10, block:5676
[task_key]52 send qps is: 5686
[task_key]1652157869703, total:5686, pass:16, block:5670
```

case 2:
另外一种情况,flowRule挺大,taskRule挺小,这个也基本没效果,期望应该是flowRule QPS达到10了,taskRule限流了,实际却不是。
```
flowRule.setCount(100);
taskRule.setCount(10);

[flow_key]72 send qps is: 5718
[flow_key]1652158022363, total:5718, pass:101, block:5617
[task_key]70 send qps is: 5746
[task_key]1652158023367, total:5746, pass:12, block:5734
[flow_key]70 send qps is: 5743
[flow_key]1652158023367, total:5743, pass:100, block:5643
[flow_key]68 send qps is: 5608
[task_key]68 send qps is: 5606
[flow_key]1652158024368, total:5608, pass:100, block:5508
[task_key]1652158024368, total:5606, pass:11, block:5595
[flow_key]66 send qps is: 5710
[flow_key]1652158025373, total:5710, pass:100, block:5610
[task_key]66 send qps is: 5716
[task_key]1652158025373, total:5716, pass:10, block:5706
```

case 3:
测试下来,只有qps足够大,并且差距够大的情况下,关联限流能够明显生效。
```
flowRule.setCount(1000);
taskRule.setCount(100);

[flow_key]1652158155726, total:5680, pass:1000, block:4679
[task_key]91 send qps is: 5689
[task_key]1652158155727, total:5689, pass:0, block:5689
[flow_key]90 send qps is: 5681
[flow_key]1652158156731, total:5681, pass:1000, block:4681
[task_key]89 send qps is: 5665
[task_key]1652158156732, total:5665, pass:0, block:5665
```

其他情况基本都很难看到实际的效果,或者是我的使用方式有问题?

Contributor guide

Open the contributing guide

Research direction

Reproduce the three cases using the FlowRule and FlowRuleManager.loadRules configuration shown, especially STRATEGY_RELATE with FLOW_KEY and TASK_KEY. Compare the observed pass and block counts with the expected related-limiting behavior at each threshold; done means the behavior is explained and the reported mismatch is resolved or documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.