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

Flow control by frequent (hot spot) parameters #156

Merged
merged 19 commits into from
Sep 27, 2018

Conversation

sczyh30
Copy link
Member

@sczyh30 sczyh30 commented Sep 24, 2018

Describe what this PR does / why we need it

In some circumstances, users may want to do flow control by frequent (hot spot) parameters. For example:

  • userId as parameter, limit top-frequent users
  • productId as parameter, limit invocations on relevant services for top-N products

Like normal flow control, flow control by frequent parameters support two mode: QPS (default) and thread count.

Does this pull request fix one issue?

Closes #32

Describe how you did it

  • Add a new module sentinel-parameter-flow-control under sentinel-extension
  • Add a CacheMap interface to provide abstraction for cache. We use ConcurrentLinkedHashMap as the default implementation (LRU strategy).
  • Add a ParameterMetric class as frequent parameter metrics for a specific resource. The metric map is located in ParamFlowSlot rather than ClusterNode
  • Implement ParameterLeapArray as statistic data structure for frequent parameters in a period of time window
  • Add ParamFlowSlot as the checker slot; Add ParamFlowChecker to do rule checking; Add ParamFlowRuleManager to do rule managing
  • The statistic metrics for frequent parameters is enabled only if the related resource has configured parameter flow rule.
  • Add callback registry for statistic slot for extensions
  • Leverage extensible SlotChainBuilder to provide a HotParamSlotChainBuilder

Describe how to verify it

See test cases and demo.

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
- Use `ConcurrentLinkedHashMap` library directly

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
@sczyh30 sczyh30 added the to-review To review label Sep 24, 2018
@sczyh30 sczyh30 self-assigned this Sep 24, 2018
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
@codecov-io
Copy link

codecov-io commented Sep 24, 2018

Codecov Report

Merging #156 into master will increase coverage by 1.47%.
The diff coverage is 54.65%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #156      +/-   ##
============================================
+ Coverage     50.01%   51.49%   +1.47%     
- Complexity      690      878     +188     
============================================
  Files           122      141      +19     
  Lines          4213     5166     +953     
  Branches        577      770     +193     
============================================
+ Hits           2107     2660     +553     
- Misses         1867     2207     +340     
- Partials        239      299      +60
Impacted Files Coverage Δ Complexity Δ
...ots/statistic/ParamFlowStatisticEntryCallback.java 0% <0%> (ø) 0 <0> (?)
...tinel/init/ParamFlowStatisticSlotCallbackInit.java 0% <0%> (ø) 0 <0> (?)
...nd/handler/ModifyParamFlowRulesCommandHandler.java 0% <0%> (ø) 0 <0> (?)
.../command/handler/FetchTopParamsCommandHandler.java 0% <0%> (ø) 0 <0> (?)
...mmand/handler/GetParamFlowRulesCommandHandler.java 0% <0%> (ø) 0 <0> (?)
...a/csp/sentinel/slots/HotParamSlotChainBuilder.java 0% <0%> (ø) 0 <0> (?)
.../sentinel/slots/statistic/data/ParamMapBucket.java 100% <100%> (ø) 8 <8> (?)
...inel/slots/block/flow/param/RollingParamEvent.java 100% <100%> (ø) 1 <1> (?)
...ba/csp/sentinel/slots/statistic/StatisticSlot.java 61.11% <11.11%> (-11.62%) 10 <0> (ø)
...slots/statistic/StatisticSlotCallbackRegistry.java 22.22% <22.22%> (ø) 3 <3> (?)
... and 46 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 9e012d2...e1c394f. Read the comment docs.

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
@sczyh30 sczyh30 force-pushed the feature/hot-param-flow-control branch from c0e60d7 to 7b4acd5 Compare September 25, 2018 09:23
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Signed-off-by: Eric Zhao <sczyh16@gmail.com>
Copy link
Contributor

@CarpenterLee CarpenterLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sczyh30 sczyh30 merged commit 88a0262 into master Sep 27, 2018
@sczyh30 sczyh30 removed the to-review To review label Sep 27, 2018
@sczyh30 sczyh30 deleted the feature/hot-param-flow-control branch September 27, 2018 12:12
Arlmls pushed a commit to Arlmls/Sentinel that referenced this pull request Jan 8, 2019
- Add callback registry for statistic slot for extensions.
- Add a new module `sentinel-parameter-flow-control` under `sentinel-extension`.
- Add a `CacheMap` interface to provide abstraction for cache. We use ConcurrentLinkedHashMap as the default implementation (LRU strategy)..
- Add a `ParameterMetric` class as frequent parameter metrics for a specific resource. The metric map is located in `ParamFlowSlot` rather than `ClusterNode`.
- Implement `ParameterLeapArray` as statistic data structure for frequent parameters in a period of time window.
- Add `ParamFlowSlot` as the checker slot; Add `ParamFlowChecker` to do rule checking; Add `ParamFlowRuleManager` to do rule managing.
- The statistic metrics for frequent parameters is enabled only if the related resource has configured parameter flow rule; Parameter metrics for removed rules will be cleared automatically.
- Leverage extensible `SlotChainBuilder` to provide a `HotParamSlotChainBuilder`.
- Add command handlers for hot param rules.
- Add test cases and demo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] Flow control by frequent ("hot spot") parameters
3 participants