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

[feature]Adaptive Flow Control with Q learning algorithm #1673

Closed
wants to merge 64 commits into from

Conversation

mastertiller
Copy link

@mastertiller mastertiller commented Aug 18, 2020

Describe what this PR does / why we need it

在服务数量多,拓扑复杂,处理能力逐渐变化的情况下,使用固定的最大并发会带来巨大的测试工作量,并且用户需要手动地设置很多流控规则。自适应限流就是为了解决这个问题。我们希望使用Q-Learning算法,引入智能的自适应流控策略进行限流,在最大化吞吐量的同时保障系统服务的稳定。相关issue可见#748 #1641

Does this pull request fix one issue?

#748

Describe how you did it

使用强化学习Q-Learning算法实现自适应流控。
QLearningLearner.java实现了算法的迭代更新。
QLearningMetric.java实现了算法的主要方法与参数设置。
QTableStorage.java实现QTable的读写与存储。
QInfo.java存储了决策前状态(state)、行为(action)、效用(utility)的信息。

Describe how to verify it

sentinel-demo/sentinel-demo-basic/src/main/java/com/alibaba/csp/sentinel/demo/qlearning/UserPeakCpuDemo.java 实现了简单的峰值流量场景测试。
测试时,isTraining为false,不更新QTable。
训练时,将isTraining设为true,可以更新QTable。
启用QLearning的开关为isQLearning,设置为false时,不使用QLearning算法进行自适应流控。

Special notes for reviews

@CLAassistant
Copy link

CLAassistant commented Aug 18, 2020

CLA assistant check
All committers have signed the CLA.

@mastertiller mastertiller changed the title Add QLearning Algorithm [feature]Adaptive Flow Control with Q learning algorithm Aug 18, 2020
@sczyh30 sczyh30 added the area/adaptive-traffic-shaping Issues or PRs related to adaptive traffic shaping label Aug 18, 2020
@yunfeiyanggzq
Copy link
Contributor

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.
mastertiller seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

please sign the CLA.

mastertiller and others added 26 commits August 20, 2020 20:51
Introduce support through a customized client builder `SentinelApacheHttpClientBuilder`.
- One config per interceptor instead of the global config
- Polish document and demo

Signed-off-by: Eric Zhao <[email protected]>
…rove strategy

* Add `CircuitBreaker` abstraction (with half-open state) and add circuit breaker state change event observer support.
* Improve circuit breaking strategy (avg RT → slow request ratio) and make statistics of each rule dependent (to support arbitrary statistic interval).
* Add simple "trial" mechanism (aka. half-open).
* Refactor mechanism of metric recording and state change handling for circuit breakers: record RT and error when requests have completed (i.e. `onExit`, based on alibaba#1420).

Signed-off-by: Eric Zhao <[email protected]>
liqiangz and others added 11 commits August 20, 2020 20:51
- Fix NPE bug in consumer filter (when non-biz error occurred)
- Improve default fallback in Dubbo 2.7.x adapter: convert the BlockException to a simple RuntimeException (with necessary message)
- Polish code and comments

Signed-off-by: Eric Zhao <[email protected]>
…terGlobalConfig (alibaba#1572)

* Unify Dubbo callback registry (for fallback and origin parser) into DubboAdapterGlobalConfig
* Polish default fallback implementation (wrap exception with RpcResult rather than directly throw it out)

Signed-off-by: Eric Zhao <[email protected]>
…terGlobalConfig (alibaba#1572)

* Unify Dubbo callback registry (for fallback and origin parser) into DubboAdapterGlobalConfig
* Polish default fallback implementation (wrap exception with RpcResult rather than directly throw it out)

Signed-off-by: Eric Zhao <[email protected]>
…terGlobalConfig (alibaba#1572)

* Unify Dubbo callback registry (for fallback and origin parser) into DubboAdapterGlobalConfig
* Polish default fallback implementation (wrap exception with RpcResult rather than directly throw it out)

Signed-off-by: Eric Zhao <[email protected]>
cityiron and others added 17 commits August 20, 2020 20:56
…terGlobalConfig (alibaba#1572)

* Unify Dubbo callback registry (for fallback and origin parser) into DubboAdapterGlobalConfig
* Polish default fallback implementation (wrap exception with RpcResult rather than directly throw it out)

Signed-off-by: Eric Zhao <[email protected]>
…terGlobalConfig (alibaba#1572)

* Unify Dubbo callback registry (for fallback and origin parser) into DubboAdapterGlobalConfig
* Polish default fallback implementation (wrap exception with RpcResult rather than directly throw it out)

Signed-off-by: Eric Zhao <[email protected]>
…terGlobalConfig (alibaba#1572)

* Unify Dubbo callback registry (for fallback and origin parser) into DubboAdapterGlobalConfig
* Polish default fallback implementation (wrap exception with RpcResult rather than directly throw it out)

Signed-off-by: Eric Zhao <[email protected]>
…terGlobalConfig (alibaba#1572)

* Unify Dubbo callback registry (for fallback and origin parser) into DubboAdapterGlobalConfig
* Polish default fallback implementation (wrap exception with RpcResult rather than directly throw it out)

Signed-off-by: Eric Zhao <[email protected]>
…terGlobalConfig (alibaba#1572)

* Unify Dubbo callback registry (for fallback and origin parser) into DubboAdapterGlobalConfig
* Polish default fallback implementation (wrap exception with RpcResult rather than directly throw it out)

Signed-off-by: Eric Zhao <[email protected]>
…terGlobalConfig (alibaba#1572)

* Unify Dubbo callback registry (for fallback and origin parser) into DubboAdapterGlobalConfig
* Polish default fallback implementation (wrap exception with RpcResult rather than directly throw it out)

Signed-off-by: Eric Zhao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/adaptive-traffic-shaping Issues or PRs related to adaptive traffic shaping
Projects
None yet
Development

Successfully merging this pull request may close these issues.