-
Notifications
You must be signed in to change notification settings - Fork 722
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: implement token assignment in server #5809
resource_manager: implement token assignment in server #5809
Conversation
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. |
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.
roken? token?
Codecov ReportBase: 75.40% // Head: 75.45% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #5809 +/- ##
==========================================
+ Coverage 75.40% 75.45% +0.04%
==========================================
Files 338 338
Lines 33774 33859 +85
==========================================
+ Hits 25468 25548 +80
- Misses 6113 6120 +7
+ Partials 2193 2191 -2
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. |
type GroupTokenBucket struct { | ||
*rmpb.TokenBucket `json:"token_bucket,omitempty"` | ||
Consumption *rmpb.TokenBucketsRequest `json:"consumption,omitempty"` | ||
LastUpdate *time.Time `json:"last_update,omitempty"` | ||
Initialized bool `json:"initialized"` | ||
LoanExpireTime *time.Time `json:"loan_time,omitempty"` |
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.
Add comments about the loan.
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 link the issue.
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
for _, req := range request.Requests { | ||
rg := s.manager.GetResourceGroup(req.ResourceGroupName) | ||
if rg == nil { | ||
return errors.New("resource group not found") |
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.
A logical error should not exit the main loop. Should set a error message in the response instead.
} | ||
} | ||
case rmpb.GroupMode_NativeMode: | ||
return errors.New("not supports the resource type") |
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.
ditto.
var res rmpb.TokenBucket | ||
res.Settings = &rmpb.TokenLimitSettings{} | ||
// TODO: consider the shares for dispatch the fill rate | ||
res.Settings.Fillrate = 0 |
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 it's used for the token server unavailable in abnormal situation.
} else { | ||
et := t.LastUpdate.Add(t.LoanMaxPeriod) | ||
t.LoanExpireTime = &et | ||
periodFilled = float64(t.Settings.Fillrate) * (1 - loanReserveRatio) * t.LoanMaxPeriod.Seconds() |
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.
Do we need to ensure LoadMaxPeriod
period greater than targetPeriodMs
?
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.
Yes
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.
and why not periodFilled = float64(t.Settings.Fillrate) * (1 - loanReserveRatio) * trickleTime
?
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.
periodFilled is the number of tokens that can be allocated in whole loan period, so I think we should use LoanMaxPeriod
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 it will make the tokens not be graceful consumed with Fillrate
in the loan period. Client will consume more tokens in target period(loan expire period> target period)
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 guess that you want the consumption curve to be smoother. To fit this situation, we can use shorter LoanMaxPeriod
. We can use long LoanMaxPeriod for high credit or important resource group, so they can respond more promptly to qps peaks.
periodFilled = float64(t.Settings.Fillrate) * (1 - loanReserveRatio) * t.LoanMaxPeriod.Seconds() | ||
} | ||
periodFilled += t.Tokens | ||
if periodFilled <= float64(t.Settings.Fillrate)*loanReserveRatio { |
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 * trickleTime
?
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@CabinfeverB Has some conflicts. |
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
// Request requests tokens from the token bucket. | ||
func (t *GroupTokenBucket) Request( | ||
// request requests tokens from the token bucket. | ||
func (t *GroupTokenBucket) request( |
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 request
and update
can be one function, also reduce the code functions.
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
switch re.Type { | ||
case rmpb.RequestUnitType_RRU: | ||
tokens := rg.RequestRRU(now, re.Value, targetPeriodMs) | ||
resp.GrantedRUTokens = append(resp.GrantedRUTokens, tokens) | ||
case rmpb.RequestUnitType_WRU: | ||
tokens := rg.RequestWRU(now, re.Value, targetPeriodMs) | ||
resp.GrantedRUTokens = append(resp.GrantedRUTokens, 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.
switch re.Type { | |
case rmpb.RequestUnitType_RRU: | |
tokens := rg.RequestRRU(now, re.Value, targetPeriodMs) | |
resp.GrantedRUTokens = append(resp.GrantedRUTokens, tokens) | |
case rmpb.RequestUnitType_WRU: | |
tokens := rg.RequestWRU(now, re.Value, targetPeriodMs) | |
resp.GrantedRUTokens = append(resp.GrantedRUTokens, tokens) | |
} | |
switch re.Type { | |
case rmpb.RequestUnitType_RRU: | |
tokens := rg.RequestRRU(now, re.Value, targetPeriodMs) | |
case rmpb.RequestUnitType_WRU: | |
tokens := rg.RequestWRU(now, re.Value, targetPeriodMs) | |
} | |
resp.GrantedRUTokens = append(resp.GrantedRUTokens, tokens) |
|
||
// GroupTokenBucket is a token bucket for a resource group. | ||
// TODO: statistics Consumption |
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.
// TODO: statistics Consumption | |
// TODO: statistics consumption @JmPotato |
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
// MaxTokens limits the number of tokens that can be accumulated | ||
MaxTokens float64 `json:"max_tokens,omitempty"` | ||
|
||
Consumption *rmpb.TokenBucketsRequest `json:"consumption,omitempty"` |
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.
Consumption *rmpb.TokenBucketsRequest `json:"consumption,omitempty"` | |
Consumption *rmpb.Consumption `json:"consumption,omitempty"` |
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
/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: 3896b95
|
@CabinfeverB: Your PR was out of date, I have automatically updated it for you. If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. 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. |
Signed-off-by: Cabinfever_B cabinfeveroier@gmail.com
What problem does this PR solve?
Issue Number: Close #5822
What is changed and how does it work?
Check List
Tests
Code changes
Side effects
Related changes
pingcap/docs
/pingcap/docs-cn
:pingcap/tiup
:Release note