You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2020/07/29 07:29:06 UTC
[GitHub] [servicecomb-java-chassis] liubao68 commented on a change in pull request #1894: [SCB-2043] flow control support custom / bug fix
liubao68 commented on a change in pull request #1894:
URL: https://github.com/apache/servicecomb-java-chassis/pull/1894#discussion_r461262652
##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -211,6 +212,8 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
String strategyKey) {
AbstractQpsStrategy strategy;
+ AbstractQpsStrategy customStrategy = SPIServiceUtils
Review comment:
Maybe this code can be better refactored.
1. all strategies are SPI
2. any implementation have a name
3. choose the target strategy by configured name and default to 'FixedWindow'
##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -211,6 +212,8 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
String strategyKey) {
AbstractQpsStrategy strategy;
+ AbstractQpsStrategy customStrategy = SPIServiceUtils
Review comment:
Maybe this code can be better refactored.
1. all strategies are SPI
2. any implementation have a name
3. choose the target strategy by configured name and default to 'FixedWindow'
By doing this, the strategy enum and case statements can be removed.
##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -211,6 +212,8 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
String strategyKey) {
AbstractQpsStrategy strategy;
+ AbstractQpsStrategy customStrategy = SPIServiceUtils
Review comment:
Hidden parameters in implementation and I think will work.
##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -211,6 +212,8 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
String strategyKey) {
AbstractQpsStrategy strategy;
+ AbstractQpsStrategy customStrategy = SPIServiceUtils
Review comment:
Hidden parameters in implementation and I think will work. You can think of users will custom strategies like this, how will they do it?
##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -210,21 +209,17 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
String strategyKey) {
- AbstractQpsStrategy strategy;
- switch (StrategyType.parseStrategyType(strategyKey)) {
- case FixedWindow:
- strategy = new FixedWindowStrategy(globalConfigKey, limit);
- break;
- case LeakyBucket:
- strategy = new LeakyBucketStrategy(globalConfigKey, limit);
- break;
- case TokenBucket:
- strategy = new TokenBucketStrategy(globalConfigKey, limit, bucket);
- break;
- case SlidingWindow:
- default:
- strategy = new FixedWindowStrategy(globalConfigKey, limit);
+ AbstractQpsStrategy strategy = new FixedWindowStrategy(globalConfigKey, limit);
Review comment:
strategyKey can have default value 'FixedWindow', wrong used defined value can throw exception. So here do not need new a default strategy.
##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -210,21 +209,17 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
String strategyKey) {
- AbstractQpsStrategy strategy;
- switch (StrategyType.parseStrategyType(strategyKey)) {
- case FixedWindow:
- strategy = new FixedWindowStrategy(globalConfigKey, limit);
- break;
- case LeakyBucket:
- strategy = new LeakyBucketStrategy(globalConfigKey, limit);
- break;
- case TokenBucket:
- strategy = new TokenBucketStrategy(globalConfigKey, limit, bucket);
- break;
- case SlidingWindow:
- default:
- strategy = new FixedWindowStrategy(globalConfigKey, limit);
+ AbstractQpsStrategy strategy = new FixedWindowStrategy(globalConfigKey, limit);
+ List<AbstractQpsStrategy> customStrategy = SPIServiceUtils
+ .getOrLoadSortedService(AbstractQpsStrategy.class);
+ for (AbstractQpsStrategy abstractQpsStrategy : customStrategy) {
+ if (abstractQpsStrategy.name().equals(strategyKey)) {
+ strategy = abstractQpsStrategy;
Review comment:
Add a break is better.
##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -210,21 +209,17 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
String strategyKey) {
- AbstractQpsStrategy strategy;
- switch (StrategyType.parseStrategyType(strategyKey)) {
- case FixedWindow:
- strategy = new FixedWindowStrategy(globalConfigKey, limit);
- break;
- case LeakyBucket:
- strategy = new LeakyBucketStrategy(globalConfigKey, limit);
- break;
- case TokenBucket:
- strategy = new TokenBucketStrategy(globalConfigKey, limit, bucket);
- break;
- case SlidingWindow:
- default:
- strategy = new FixedWindowStrategy(globalConfigKey, limit);
+ AbstractQpsStrategy strategy = new FixedWindowStrategy(globalConfigKey, limit);
+ List<AbstractQpsStrategy> customStrategy = SPIServiceUtils
+ .getOrLoadSortedService(AbstractQpsStrategy.class);
+ for (AbstractQpsStrategy abstractQpsStrategy : customStrategy) {
+ if (abstractQpsStrategy.name().equals(strategyKey)) {
Review comment:
strategyKey better to rename to 'strategy', it is not a key , but a value.
##########
File path: handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -209,22 +208,21 @@ public QpsControllerManager setGlobalQpsStrategy(String globalLimitKey, String g
}
private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long limit, Long bucket,
- String strategyKey) {
- AbstractQpsStrategy strategy;
- switch (StrategyType.parseStrategyType(strategyKey)) {
- case FixedWindow:
- strategy = new FixedWindowStrategy(globalConfigKey, limit);
- break;
- case LeakyBucket:
- strategy = new LeakyBucketStrategy(globalConfigKey, limit);
- break;
- case TokenBucket:
- strategy = new TokenBucketStrategy(globalConfigKey, limit, bucket);
- break;
- case SlidingWindow:
- default:
- strategy = new FixedWindowStrategy(globalConfigKey, limit);
+ String strategyName) {
Review comment:
strategyName do not have a default value.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org