resouce_manager: impl resource controller for tokens client#5811
resouce_manager: impl resource controller for tokens client#5811ti-chi-bot merged 41 commits intotikv:masterfrom
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. DetailsReviewer 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>
| } | ||
| 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.
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.
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.
We can compare it in another PR.
| } | ||
| } | ||
|
|
||
| func (gc *groupCostController) updateAvgResourcePerSec() { |
There was a problem hiding this comment.
| 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.
| 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.
| 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.
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.
How about add a Stop function, I may use it when resource group features disable.
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)) |
|
|
||
| var _ ResourceGroupKVInterceptor = (*resourceGroupsController)(nil) | ||
|
|
||
| type resourceGroupsController struct { |
There was a problem hiding this comment.
| 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.
| // 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.
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.
| lastedGroups := make(map[string]struct{}) | |
| latestGroups := make(map[string]struct{}) |
| 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)) |
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
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. DetailsIn 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. |
| 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.
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 { |
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 DetailsInstructions 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. DetailsCommit 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