-
Notifications
You must be signed in to change notification settings - Fork 725
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
Conversation
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Codecov ReportBase: 75.59% // Head: 75.41% // Decreases project coverage by
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
Flags with carried forward coverage won't be shown. Click here to find out 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. |
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.
plz add the changes item in the pull request description.
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
// advance time to now | ||
now, _, tokens := r.lim.advance(now) | ||
// calculate new number of tokens | ||
tokens += float64(r.tokens) |
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.
need address the lint check.
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
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.
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. |
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.
// 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, |
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.
ok is false, is the tokens field useless?
tokens: n, | ||
timeToAct: now, | ||
} | ||
} else if n > maxRequestTokens { |
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.
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) { |
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.
Using the word At
is a little bit confusing for the caller. They may be confused about which parameter this At
refers to.
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 |
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.
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>
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
/merge |
@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. |
This pull request has been accepted and is ready to merge. Commit hash: 122c52b
|
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, andWaitReservations
takes example byWait
method to handle multiple reservations. I also modified the reservation cancel function, once cancel, restore all the tokens.Check List
Tests
Release note