-
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
scheduler: allow balance-leader-scheduler
generate multiple operators
#4652
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. |
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #4652 +/- ##
==========================================
+ Coverage 75.03% 75.06% +0.02%
==========================================
Files 284 284
Lines 27942 27985 +43
==========================================
+ Hits 20966 21006 +40
- Misses 5110 5111 +1
- Partials 1866 1868 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
balance-leader-scheduler
generate multiple operators
@@ -821,6 +821,14 @@ func (oc *OperatorController) GetFastOpInfluence(cluster Cluster, influence oper | |||
} | |||
} | |||
|
|||
// AddOpInfluence add operator influence for cluster | |||
func AddOpInfluence(op *operator.Operator, influence operator.OpInfluence, cluster Cluster) { |
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 is it used for?
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.
change store leader score to sort again
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.
Could we use this function on L841-845 in the function NewTotalOpInfluence
?
server/schedulers/balance_leader.go
Outdated
@@ -51,6 +51,13 @@ func init() { | |||
} | |||
conf.Ranges = ranges | |||
conf.Name = BalanceLeaderName | |||
conf.Batch = 1 | |||
if len(args) > len(ranges)*2 { |
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 there is no need to change it.
server/schedulers/balance_leader.go
Outdated
@@ -161,48 +170,70 @@ func (l *balanceLeaderScheduler) Schedule(cluster schedule.Cluster) []*operator. | |||
targets[j].LeaderScore(leaderSchedulePolicy, jOp) | |||
}) | |||
|
|||
usedStores := make(map[uint64]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.
I think the stores can be used more than once.
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.
has changed
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
/cc @HunDunDM |
server/schedulers/balance_leader.go
Outdated
return result | ||
} | ||
|
||
func sortStores(stores []*core.StoreInfo, pos int, less func(i, j int) 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.
How about resortStores
?
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.
fix
server/schedulers/balance_leader.go
Outdated
sourcePoint := 0 | ||
targetPoint := 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 at least some comments are needed.
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.
rafactor it
server/schedulers/balance_leader.go
Outdated
@@ -51,6 +51,7 @@ func init() { | |||
} | |||
conf.Ranges = ranges | |||
conf.Name = BalanceLeaderName | |||
conf.Batch = 5 |
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 using a constant?
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.
fix
server/schedulers/balance_leader.go
Outdated
for sourcePoint < len(sources) || targetPoint < len(targets) { | ||
if sourcePoint < len(sources) { | ||
used := false | ||
plan.source, plan.target = sources[sourcePoint], nil | ||
retryLimit := l.retryQuota.GetLimit(plan.source) | ||
log.Debug("store leader score", zap.String("scheduler", l.GetName()), zap.Uint64("source-store", plan.SourceStoreID())) | ||
l.counter.WithLabelValues("high-score", plan.SourceMetricLabel()).Inc() | ||
for j := 0; j < retryLimit; j++ { | ||
schedulerCounter.WithLabelValues(l.GetName(), "total").Inc() | ||
if ops := l.transferLeaderOut(plan); len(ops) > 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.
How about changing it to op
?
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.
fix
server/schedulers/balance_leader.go
Outdated
for sourcePoint < len(sources) || targetPoint < len(targets) { | ||
if sourcePoint < len(sources) { | ||
used := false | ||
plan.source, plan.target = sources[sourcePoint], nil |
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 index?
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.
yep, updated
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@@ -821,6 +821,14 @@ func (oc *OperatorController) GetFastOpInfluence(cluster Cluster, influence oper | |||
} | |||
} | |||
|
|||
// AddOpInfluence add operator influence for cluster | |||
func AddOpInfluence(op *operator.Operator, influence operator.OpInfluence, cluster Cluster) { |
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.
Could we use this function on L841-845 in the function NewTotalOpInfluence
?
server/schedulers/balance_leader.go
Outdated
sort.Slice(bc.targets, func(i, j int) bool { | ||
iOp := bc.plan.GetOpInfluence(bc.targets[i].GetID()) | ||
jOp := bc.plan.GetOpInfluence(bc.targets[j].GetID()) | ||
return bc.targets[i].LeaderScore(bc.plan.kind.Policy, iOp) < |
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 defining two functions? With the name of the function, the maintainer can easily find the slice is ordered by desc or asc.
server/schedulers/balance_leader.go
Outdated
|
||
// hasOptionalStore returns whether there is remaining and optional stores | ||
func (bc *batchController) hasOptionalStore() bool { | ||
return bc.sourceIndex < len(bc.sources) || bc.targetIndex < len(bc.targets) |
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.
return bc.sourceIndex < len(bc.sources) || bc.targetIndex < len(bc.targets) | |
return bc.hasOptionalSourceStore() || bc.hasOptionalTargetStore() |
server/schedulers/balance_leader.go
Outdated
return bc.sourceIndex < len(bc.sources) || bc.targetIndex < len(bc.targets) | ||
} | ||
|
||
// hasOptionalSourceStore returns whether there is remaining and optional source stores |
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
`hasSourceStore` returns true when there are leftover source stores.
Some functions are only used once and it's so easy. For these functions, adding some comments is enough. |
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
server/schedulers/balance_leader.go
Outdated
store := cs.getStore() | ||
retryLimit := l.retryQuota.GetLimit(store) | ||
var creator func(*balancePlan) *operator.Operator | ||
log.Debug("store leader score", zap.String("scheduler", l.GetName()), zap.Uint64(dir, store.GetID())) |
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.
no score field?
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 statement didn't have it before, but it's better to add it.
server/schedulers/balance_leader.go
Outdated
l.counter.WithLabelValues("low-score", plan.TargetMetricLabel()).Inc() | ||
creator = l.transferLeaderIn | ||
} | ||
var op *operator.Operator = nil |
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.
var op *operator.Operator = nil | |
var op *operator.Operator |
server/schedulers/balance_leader.go
Outdated
} | ||
} | ||
|
||
func leaderScore(store *core.StoreInfo, plan *balancePlan) 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.
I prefer to remove this function and move GetOpInfluence directly into xxxOption
.
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
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
/merge |
@nolouch: 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: 9a32d17
|
Signed-off-by: Cabinfever_B cabinfeveroier@gmail.com
What problem does this PR solve?
Issue Number: ref #4610
speed up balance leader
What is changed and how it works?
Add a Batch param like #4008 that the scheduler can generate multi operators.
Check List
Tests
Release note