-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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: support flow limiting control for a single server #4053
base: 2.x
Are you sure you want to change the base?
Conversation
RateLimiter ratelimiter = EnhancedServiceLoader.load(RateLimiter.class); | ||
ratelimiterMap.put(transactionRequest.getClass(), ratelimiter); | ||
} | ||
if (!ratelimiterMap.get(transactionRequest.getClass()).canPass()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return limit information to client.
@@ -151,6 +157,8 @@ | |||
|
|||
private static volatile DefaultCoordinator instance; | |||
|
|||
private Map<Class, RateLimiter> ratelimiterMap = new ConcurrentHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warp the map into a class. In addition, not all types need limiting.
Codecov Report
@@ Coverage Diff @@
## 2.0.0 #4053 +/- ##
============================================
+ Coverage 49.08% 49.23% +0.14%
+ Complexity 3772 3752 -20
============================================
Files 719 702 -17
Lines 23948 23653 -295
Branches 2926 2919 -7
============================================
- Hits 11755 11645 -110
+ Misses 10989 10823 -166
+ Partials 1204 1185 -19
|
this.microSecondsPerToken = TimeUnit.SECONDS.toMicros(1L) / requestsPerSecond; | ||
this.burst = CONFIG.getInt(ConfigurationKeys.BURST, (int)microSecondsPerToken); | ||
this.burst = Double.parseDouble(CONFIG.getConfig(ConfigurationKeys.BURST, String.valueOf(requestsPerSecond))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the configuration content not a parsable double, throw exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@YSF-A Pls pay attention to the following unit test failure. |
server/src/main/java/io/seata/server/coordinator/DefaultCoordinator.java
Show resolved
Hide resolved
server/src/main/java/io/seata/server/ratelimit/RateLimitedResponseMap.java
Outdated
Show resolved
Hide resolved
server/src/main/java/io/seata/server/ratelimit/TokenBucketLimiter.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
public boolean acquire() { | ||
long waitTimeInMicros = tryGetTokenWithDelay(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果允许delay,应该加上timeout参数,在允许的实际内自旋/sleep等待令牌,如果超出了时间没得到应该失败,而不是等一会直接就允许通过
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeout 是否应该放在入参一份,以便不同场景都可复用,当timeout为空再用配置中心的配置
server/src/test/java/io/seata/server/ratelimit/TokenBucketRateLimiterTest.java
Outdated
Show resolved
Hide resolved
…ceptionCode.java and transactionExceptionCode.proto
This pull request introduces 7 alerts when merging c337b96 into 6f877fa - view on LGTM.com new alerts:
|
|
Ⅰ. Describe what this PR did
Support flow limiting control for a single server
Ⅱ. Does this pull request fix one issue?
fixes #3747
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews