-
Notifications
You must be signed in to change notification settings - Fork 728
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
resouce_manager: impl resource controller for tokens client #5811
resouce_manager: impl resource controller for tokens client #5811
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. |
Codecov ReportBase: 75.51% // Head: 75.69% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #5811 +/- ##
==========================================
+ Coverage 75.51% 75.69% +0.18%
==========================================
Files 341 342 +1
Lines 34413 34829 +416
==========================================
+ Hits 25986 26363 +377
- Misses 6191 6223 +32
- Partials 2236 2243 +7
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. |
Signed-off-by: JmPotato <ghzpotato@gmail.com>
Signed-off-by: JmPotato <ghzpotato@gmail.com>
a915b08
to
9141699
Compare
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
} | ||
log.Info("create resource group cost controller", zap.String("name", group.GetName())) | ||
gc := newGroupCostController(group, c.config, c.lowTokenNotifyChan) | ||
gc.initRunState() |
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 future case: If user change mode from RU to RAW mode. it need re-init?
if err != nil { | ||
return err | ||
} | ||
gc.mu.Lock() |
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.
This is in hot path, we may need to do some benchmark later. BTW, maybe we can compare it with the buffer channel.
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.
We can compare it in another PR.
} | ||
} | ||
|
||
func (gc *groupCostController) updateAvgResourcePerSec() { |
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.
func (gc *groupCostController) updateAvgResourcePerSec() { | |
func (gc *groupCostController) updateAvgRaWResourcePerSec() { |
|
||
func (gc *groupCostController) updateAvgResourcePerSec() { | ||
for typ, counter := range gc.run.resourceTokens { | ||
if !gc.calcAvg(counter, getResourceValueFromConsumption(gc.run.consumption, typ)) { |
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.
if !gc.calcAvg(counter, getResourceValueFromConsumption(gc.run.consumption, typ)) { | |
if !gc.calcAvg(counter, getRawResourceValueFromConsumption(gc.run.consumption, typ)) { |
if !gc.calcAvg(counter, getResourceValueFromConsumption(gc.run.consumption, typ)) { | ||
continue | ||
} | ||
log.Debug("[resource group controllor] update avg ru per sec", zap.String("name", gc.Name), zap.String("type", rmpb.RawResourceType_name[int32(typ)]), zap.Float64("avgRUPerSec", counter.avgRUPerSec)) |
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.
log.Debug("[resource group controllor] update avg ru per sec", zap.String("name", gc.Name), zap.String("type", rmpb.RawResourceType_name[int32(typ)]), zap.Float64("avgRUPerSec", counter.avgRUPerSec)) | |
log.Debug("[resource group controllor] update avg raw resource per sec", zap.String("name", gc.Name), zap.String("type", rmpb.RawResourceType_name[int32(typ)]), zap.Float64("avgRUPerSec", counter.avgRUPerSec)) |
} | ||
|
||
var cfg tokenBucketReconfigureArgs | ||
if trickleTimeMs == 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.
maybe we need some comments, here is main difference.
} | ||
|
||
// Start starts resourceGroupController service | ||
func (c *resourceGroupsController) Start(ctx context.Context) error { |
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.
How about add a Stop
function, I may use it when resource group features disable.
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 like it
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
TargetRequestPeriodMs: uint64(c.config.targetPeriod / time.Millisecond), | ||
} | ||
go func() { | ||
log.Info("[resource group controllor] send token bucket request", zap.Time("now", now), zap.Any("req", req.Requests), zap.String("source", source)) |
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.
Debug level.
|
||
var _ ResourceGroupKVInterceptor = (*resourceGroupsController)(nil) | ||
|
||
type resourceGroupsController struct { |
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.
type resourceGroupsController struct { | |
type ResourceGroupsController struct { |
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@@ -0,0 +1,790 @@ | |||
// Copyright 2022 TiKV Project Authors. |
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.
// Copyright 2022 TiKV Project Authors. | |
// Copyright 2023 TiKV Project Authors. |
} | ||
|
||
// Start starts resourceGroupController service | ||
func (c *ResourceGroupsController) Start(ctx context.Context) error { |
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.
This function doesn't need to return anything.
if err != nil { | ||
return err | ||
} | ||
lastedGroups := make(map[string]struct{}) |
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.
lastedGroups := make(map[string]struct{}) | |
latestGroups := make(map[string]struct{}) |
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.
reaming @CabinfeverB
name := res.GetResourceGroupName() | ||
v, ok := c.groupsController.Load(name) | ||
if !ok { | ||
log.Warn("A non-existent resource group was found when handle token response.", zap.String("name", name)) |
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.
Shouldn't we continue here?
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
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@BornChanger: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments. In response to this: 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. |
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.
The rest LGTM.
func (c *ResourceGroupsController) OnRequestWait( | ||
ctx context.Context, resourceGroupName string, info RequestInfo, | ||
) (err error) { | ||
if _, ok := defaultWhiteList[resourceGroupName]; ok { |
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.
This check could be done by https://github.com/tikv/client-go/pull/648/files#diff-34812587e42268a5d84933be286601fc58fdff17ab336b09ba75455ffe5ed447R96. I prefer keeping it there.
|
||
// OnResponse is used to consume tokens atfer receiving response | ||
func (c *ResourceGroupsController) OnResponse(_ context.Context, resourceGroupName string, req RequestInfo, resp ResponseInfo) error { | ||
if _, ok := defaultWhiteList[resourceGroupName]; ok { |
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.
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
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: 37abfa8
|
Signed-off-by: Cabinfever_B cabinfeveroier@gmail.com
What problem does this PR solve?
Issue Number: ref #5851
What is changed and how does it work?
Check List
Tests
Release note