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

ratelimit: impl BBR-like algorithm #7246

Open
wants to merge 32 commits into
base: master
Choose a base branch
from

Conversation

CabinfeverB
Copy link
Member

@CabinfeverB CabinfeverB commented Oct 23, 2023

What problem does this PR solve?

Issue Number: ref #7167
should be merged after #7239

What is changed and how does it work?

We implmented a BBR like algorithm.

  1. Divide the time window into multiple time buckets of equal duration. Initialize a counter for each time bucket to keep track of the concurrency change.

  2. Monitor the concurrency of requests. When request comes, increment the counter of arrival time bucket. When processed request, decrease the counter of pass time bucket.

  3. Monitor the amount of pass requests. When processed request, increment the counter.

  4. Record the processing duration.

  5. Periodically, check the counters in each time bucket to analyze the concurrency change. If the value of any counter increases continuously over a certain threshold for a consecutive number of time buckets, it indicates the API is reaching its maximum concurrency:

    • We divided the time window into multiple time buckets and counted the change of concurrency in each time bucket.

$$ \sum_{i=1}^{bucket_{size}} b_i \geq 1 $$

$$ p_i = \begin{cases} 1 &\text{if } b_i > 0\\ 0 &\text{if } b_i \leq 0\ \end{cases} $$

$$ n_i = \begin{cases} 1 &\text{if } b_i < 0\\ 0 &\text{if } b_i \geq 0\ \end{cases} $$

    For every 

$$ \forall i,  \sum_{j=1}^{i} p_i \geq \sum_{j=1}^{i} n_i $$

    And 

$$ \sum_{i=1}^{bucket_ size/2} b_i \geq 1 $$

  1. According the maxinum pass request and minimum duration, calculate RDP and use it as conccurency limit.

Check List

Tests

  • Unit test

Code changes

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

Release note

None.

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Oct 23, 2023

[REVIEW NOTIFICATION]

This pull request has not been approved.

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Oct 23, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 23, 2023
@ti-chi-bot ti-chi-bot bot requested review from nolouch and rleungx October 23, 2023 10:26
@CabinfeverB CabinfeverB changed the title Rate limit/bbr v1 ratelimit: impl BBR-like algorithm Oct 26, 2023
@CabinfeverB CabinfeverB marked this pull request as ready for review October 26, 2023 15:11
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 26, 2023
Signed-off-by: Cabinfever_B <[email protected]>
Signed-off-by: Cabinfever_B <[email protected]>
pkg/ratelimit/bbr.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 5, 2024
Signed-off-by: Cabinfever_B <[email protected]>
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 6, 2024
Signed-off-by: Cabinfever_B <[email protected]>
Copy link

codecov bot commented Feb 6, 2024

Codecov Report

Merging #7246 (b13305c) into master (37be34e) will increase coverage by 0.01%.
Report is 97 commits behind head on master.
The diff coverage is 94.81%.

❗ Current head b13305c differs from pull request most recent head 348076e. Consider uploading reports for the commit 348076e to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7246      +/-   ##
==========================================
+ Coverage   73.47%   73.48%   +0.01%     
==========================================
  Files         432      433       +1     
  Lines       47842    48014     +172     
==========================================
+ Hits        35151    35285     +134     
- Misses       9648     9672      +24     
- Partials     3043     3057      +14     
Flag Coverage Δ
unittests 73.48% <94.81%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Signed-off-by: Cabinfever_B <[email protected]>
@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 7, 2024
Signed-off-by: Cabinfever_B <[email protected]>
Signed-off-by: Cabinfever_B <[email protected]>
Signed-off-by: Cabinfever_B <[email protected]>
@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 9, 2024
Copy link
Contributor

ti-chi-bot bot commented Apr 9, 2024

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants