pd icon indicating copy to clipboard operation
pd copied to clipboard

ratelimit: impl `BBR-like` algorithm

Open CabinfeverB opened this issue 1 year ago • 4 comments

What problem does this PR solve?

Issue Number: ref https://github.com/tikv/pd/issues/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.

CabinfeverB avatar Oct 23 '23 10:10 CabinfeverB

[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[bot] avatar Oct 23 '23 10:10 ti-chi-bot[bot]

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[bot] avatar Oct 23 '23 10:10 ti-chi-bot[bot]

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

:exclamation: 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%) :arrow_up:

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

codecov[bot] avatar Feb 06 '24 03:02 codecov[bot]

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.

ti-chi-bot[bot] avatar Apr 09 '24 10:04 ti-chi-bot[bot]