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

resource_manager: impl limiter for token controlloer #5868

Merged
merged 8 commits into from
Jan 17, 2023

Conversation

CabinfeverB
Copy link
Member

@CabinfeverB CabinfeverB commented Jan 15, 2023

What problem does this PR solve?

Issue Number: ref #5851

What is changed and how does it work?

Based on the rate limiter implemented by Go(ref to https://cs.opensource.google/go/x/time/+/refs/tags/v0.2.0:rate/rate.go), some modifications have been made.
The first is the introduction of token notification, which is sent to the channel when the threshold is below.
Second, only the Reserve method is retained, and WaitReservations takes example by Wait method to handle multiple reservations. I also modified the reservation cancel function, once cancel, restore all the tokens.

impl limiter for token controlloer

Check List

Tests

  • Unit test

Release note

None.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Jan 15, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • JmPotato
  • nolouch

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 ti-chi-bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jan 15, 2023
@CabinfeverB CabinfeverB requested review from JmPotato and nolouch and removed request for lhy1024 and HunDunDM January 15, 2023 18:27
@codecov
Copy link

codecov bot commented Jan 15, 2023

Codecov Report

Base: 75.59% // Head: 75.41% // Decreases project coverage by -0.18% ⚠️

Coverage data is based on head (d69d505) compared to base (296f062).
Patch coverage: 68.96% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5868      +/-   ##
==========================================
- Coverage   75.59%   75.41%   -0.19%     
==========================================
  Files         337      340       +3     
  Lines       34114    34290     +176     
==========================================
+ Hits        25790    25860      +70     
- Misses       6110     6200      +90     
- Partials     2214     2230      +16     
Flag Coverage Δ
unittests 75.41% <68.96%> (-0.19%) ⬇️

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

Impacted Files Coverage Δ
pkg/mcs/resource_manager/client/limiter.go 68.96% <68.96%> (ø)
pkg/dashboard/keyvisual/input/core.go 0.00% <0.00%> (-33.34%) ⬇️
server/tso/tso.go 67.97% <0.00%> (-7.87%) ⬇️
pkg/storage/kv/etcd_kv.go 65.07% <0.00%> (-7.15%) ⬇️
pkg/election/leadership.go 75.25% <0.00%> (-5.16%) ⬇️
pkg/member/member.go 62.10% <0.00%> (-2.11%) ⬇️
pkg/election/lease.go 84.05% <0.00%> (-1.45%) ⬇️
server/region_syncer/server.go 81.86% <0.00%> (-1.10%) ⬇️
server/schedule/operator_controller.go 85.97% <0.00%> (-0.91%) ⬇️
server/cluster/coordinator.go 71.59% <0.00%> (-0.76%) ⬇️
... and 14 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

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

plz add the changes item in the pull request description.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot ti-chi-bot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. release-note-none Denotes a PR that doesn't merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jan 16, 2023
// advance time to now
now, _, tokens := r.lim.advance(now)
// calculate new number of tokens
tokens += float64(r.tokens)
Copy link
Contributor

Choose a reason for hiding this comment

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

need address the lint check.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

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

rest LGTM


// reserveN is a helper method for Reserve.
// maxFutureReserve specifies the maximum reservation wait duration allowed.
// reserveN returns Reservation, not *Reservation, to avoid allocation in AllowN and WaitN.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// reserveN returns Reservation, not *Reservation, to avoid allocation in AllowN and WaitN.
// reserveN returns Reservation, not *Reservation.

return Reservation{
ok: false,
lim: lim,
tokens: lim.tokens,
Copy link
Contributor

Choose a reason for hiding this comment

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

ok is false, is the tokens field useless?

tokens: n,
timeToAct: now,
}
} else if n > maxRequestTokens {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think maxRequestTokens should be configuable , or no need maxRequestTokens in client side.

}

// SetupNotificationAt enables the notification at the given threshold.
func (lim *Limiter) SetupNotificationAt(now time.Time, threshold float64) {
Copy link
Member

Choose a reason for hiding this comment

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

Using the word At is a little bit confusing for the caller. They may be confused about which parameter this At refers to.

Suggested change
func (lim *Limiter) SetupNotificationAt(now time.Time, threshold float64) {
func (lim *Limiter) SetupNotificationThreshold(now time.Time, threshold float64) {

last time.Time
notifyThreshold float64
lowTokensNotifyChan chan struct{}
isLowProcess bool
Copy link
Member

Choose a reason for hiding this comment

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

What does this field mean? Adding a comment will be helpful.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jan 17, 2023
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 17, 2023
@JmPotato
Copy link
Member

/merge

@ti-chi-bot
Copy link
Member

@JmPotato: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

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 ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 122c52b

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jan 17, 2023
@ti-chi-bot ti-chi-bot merged commit b2a0532 into tikv:master Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants