Sentinel icon indicating copy to clipboard operation
Sentinel copied to clipboard

Adaptive flow control (Suitable for user peak and callback peak)

Open lym-ifae opened this issue 6 years ago • 4 comments

Describe what this PR does / why we need it

Nowadays users have to manually set the complex flow control rules for flow control. It is required for users to have a better understanding of Sentinel's flow control rules. It would be better if we can introduce intelligent mechanisms to do adaptive flow control automatically based on real-time metrics. Not only can the new mechanisms simplify users operations, but it can also make flow control smarter and adjust more quickly.

Does this pull request fix one issue?

#748

Describe how you did it

User peak

The scene of user peak should not have long delay. Therefore the algorithm for user peak is based on the method of token bucket.

The adjustion of the token issuance speed refers to:

  • The pass ratio which user expect to achieve;
  • The RT which user expect to less than(expectRt);
  • The CPU utilization.

The capacity of token bucket is adjusted according to the maximum requests and the token issuance rate.

Callback peak

The scene of callback peak can have the delay longer. The algorithm is based on the rate limiter which implemented by Sentinel's RateLimiterController.

The adjustion of the flow rate refers to:

  • The number of timeout requests;
  • The CPU utilization.

PID control

This method is more suitable for user peak. And the adjustion of PID controller is also based on the token bucket. Users can try this algorithm by rule.setGrade(RuleConstant.FLOW_ADAPTIVE_PID);.

We use incremental PID controller to calculate the change of CPU utilization. Our goal is to keep the CPU utilization at a certain value.

Describe how to verify it

When it comes to the scene of user peak , see TokenBucketDemo; When it comes to the scene of callback peak, see AdaptiveRateDemo.

Special notes for reviews

lym-ifae avatar Aug 21 '19 13:08 lym-ifae

Nice work. Could you please sync your branch with upstream master and resolve the conflicts (just choose accept theirs)?

sczyh30 avatar Aug 21 '19 13:08 sczyh30

Codecov Report

Merging #1007 into asoc/adaptive-flow will decrease coverage by 1.17%. The diff coverage is 11.23%.

Impacted file tree graph

@@                   Coverage Diff                    @@
##             asoc/adaptive-flow    #1007      +/-   ##
========================================================
- Coverage                 42.74%   41.57%   -1.18%     
- Complexity                 1475     1486      +11     
========================================================
  Files                       317      326       +9     
  Lines                      9280     9627     +347     
  Branches                   1267     1311      +44     
========================================================
+ Hits                       3967     4002      +35     
- Misses                     4823     5131     +308     
- Partials                    490      494       +4
Impacted Files Coverage Δ Complexity Δ
...aba/csp/sentinel/adapter/servlet/CommonFilter.java 84.61% <ø> (ø) 10 <0> (ø) :arrow_down:
...sp/sentinel/slots/block/adaptive/AdaptiveRule.java 0% <0%> (ø) 0 <0> (?)
...slots/block/adaptive/controller/PidController.java 0% <0%> (ø) 0 <0> (?)
...ntinel/slots/block/adaptive/AdaptiveException.java 0% <0%> (ø) 0 <0> (?)
...ock/adaptive/controller/TokenBucketController.java 0% <0%> (ø) 0 <0> (?)
...p/sentinel/slots/statistic/metric/ArrayMetric.java 63.75% <0%> (-3.62%) 29 <0> (ø)
...ck/adaptive/controller/AdaptiveRateController.java 0% <0%> (ø) 0 <0> (?)
...ba/csp/sentinel/slots/DefaultSlotChainBuilder.java 100% <100%> (ø) 2 <0> (ø) :arrow_down:
...sp/sentinel/slots/block/adaptive/AdaptiveSlot.java 100% <100%> (ø) 5 <5> (?)
...inel/slots/block/adaptive/AdaptiveRuleChecker.java 25% <25%> (ø) 2 <2> (?)
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 976ddf8...31a1e1e. Read the comment docs.

codecov-io avatar Aug 23 '19 09:08 codecov-io

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Jun 12 '20 07:06 CLAassistant

Please sign the CLA as per the instructions from CLAassistant.

LearningGp avatar Oct 09 '25 02:10 LearningGp