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: support flow limiting control for a single server #4053

Open
wants to merge 35 commits into
base: 2.x
Choose a base branch
from

Conversation

YSF-A
Copy link
Contributor

@YSF-A YSF-A commented Sep 30, 2021

  • I have registered the PR changes.

Ⅰ. 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

RateLimiter ratelimiter = EnhancedServiceLoader.load(RateLimiter.class);
ratelimiterMap.put(transactionRequest.getClass(), ratelimiter);
}
if (!ratelimiterMap.get(transactionRequest.getClass()).canPass()) {
Copy link
Member

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<>();
Copy link
Member

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.

@slievrly slievrly added this to the 2.0.0 milestone Oct 9, 2021
@codecov-commenter
Copy link

codecov-commenter commented Oct 9, 2021

Codecov Report

Merging #4053 (07a2b0e) into 2.0.0 (8590bbf) will increase coverage by 0.14%.
The diff coverage is 3.37%.

❗ Current head 07a2b0e differs from pull request most recent head 66a8542. Consider uploading reports for the commit 66a8542 to get more accurate results
Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
...ava/io/seata/core/constants/ConfigurationKeys.java 0.00% <ø> (ø)
...rpc/processor/server/ServerOnRequestProcessor.java 0.00% <0.00%> (ø)
...ta/spring/boot/autoconfigure/StarterConstants.java 100.00% <ø> (ø)
...configure/SeataServerEnvironmentPostProcessor.java 0.00% <0.00%> (ø)
.../io/seata/server/ratelimit/TokenBucketLimiter.java 0.00% <0.00%> (ø)
...e/properties/server/ServerRatelimitProperties.java 7.69% <7.69%> (ø)
...o/seata/server/coordinator/DefaultCoordinator.java 41.75% <25.00%> (-6.10%) ⬇️
...java/io/seata/server/metrics/MeterIdConstants.java 0.00% <0.00%> (-100.00%) ⬇️
...ava/io/seata/server/metrics/MetricsSubscriber.java 18.84% <0.00%> (-53.63%) ⬇️
... and 53 more

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)));
Copy link
Member

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?

slievrly
slievrly previously approved these changes Nov 8, 2021
Copy link
Member

@slievrly slievrly left a comment

Choose a reason for hiding this comment

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

LGTM

@slievrly
Copy link
Member

slievrly commented Nov 8, 2021

@YSF-A Pls pay attention to the following unit test failure.
image

}

public boolean acquire() {
long waitTimeInMicros = tryGetTokenWithDelay();
Copy link
Contributor

Choose a reason for hiding this comment

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

如果允许delay,应该加上timeout参数,在允许的实际内自旋/sleep等待令牌,如果超出了时间没得到应该失败,而不是等一会直接就允许通过

Copy link
Contributor

Choose a reason for hiding this comment

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

timeout 是否应该放在入参一份,以便不同场景都可复用,当timeout为空再用配置中心的配置

@YSF-A YSF-A changed the base branch from develop to 2.0.0 December 20, 2021 06:00
@YSF-A YSF-A dismissed slievrly’s stale review December 20, 2021 06:00

The base branch was changed.

@YSF-A YSF-A changed the base branch from 2.0.0 to develop December 20, 2021 06:04
@lgtm-com
Copy link

lgtm-com bot commented Dec 20, 2021

This pull request introduces 7 alerts when merging c337b96 into 6f877fa - view on LGTM.com

new alerts:

  • 7 for Query built from user-controlled sources

@YSF-A YSF-A changed the base branch from develop to 2.0.0 December 28, 2021 05:55
@YSF-A YSF-A requested a review from funky-eyes December 29, 2021 06:07
@CLAassistant
Copy link

CLAassistant commented Dec 12, 2022

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ YSF-A
❌ slievrly
You have signed the CLA already but the status is still pending? Let us recheck it.

@funky-eyes funky-eyes modified the milestones: 2.0.0, 2.x Backlog Nov 4, 2023
@slievrly slievrly changed the base branch from 2.0.0 to 2.x November 20, 2023 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Summer 2021] Enhance application protection capability of Seata-Server
5 participants