Skip to content

Commit

Permalink
scheduler: make SrcToleranceRatio and DstToleranceRatio enable fo…
Browse files Browse the repository at this point in the history
…r `stddev` (#5546)

ref #5545

Signed-off-by: lhy1024 <[email protected]>

Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
lhy1024 and ti-chi-bot authored Sep 23, 2022
1 parent 02f5639 commit 85ace3d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
7 changes: 7 additions & 0 deletions server/schedulers/hot_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ func (bs *balanceSolver) isValid() bool {
}

func (bs *balanceSolver) filterUniformStoreV1() (string, bool) {
if !bs.enableExpectation() {
return "", false
}
// Because region is available for src and dst, so stddev is the same for both, only need to calcurate one.
isUniformFirstPriority, isUniformSecondPriority := bs.isUniformFirstPriority(bs.cur.srcStore), bs.isUniformSecondPriority(bs.cur.srcStore)
if isUniformFirstPriority && isUniformSecondPriority {
Expand Down Expand Up @@ -973,6 +976,10 @@ func (bs *balanceSolver) checkByPriorityAndToleranceFirstOnly(loads []float64, f
return f(bs.firstPriority)
}

func (bs *balanceSolver) enableExpectation() bool {
return bs.sche.conf.GetDstToleranceRatio() > 0 && bs.sche.conf.GetSrcToleranceRatio() > 0
}

func (bs *balanceSolver) isUniformFirstPriority(store *statistics.StoreLoadDetail) bool {
// first priority should be more uniform than second priority
return store.IsUniform(bs.firstPriority, stddevThreshold*0.5)
Expand Down
24 changes: 14 additions & 10 deletions server/schedulers/hot_region_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,24 @@ type hotRegionSchedulerConfig struct {

// rank step ratio decide the step when calculate rank
// step = max current * rank step ratio
ByteRateRankStepRatio float64 `json:"byte-rate-rank-step-ratio"`
KeyRateRankStepRatio float64 `json:"key-rate-rank-step-ratio"`
QueryRateRankStepRatio float64 `json:"query-rate-rank-step-ratio"`
CountRankStepRatio float64 `json:"count-rank-step-ratio"`
GreatDecRatio float64 `json:"great-dec-ratio"`
MinorDecRatio float64 `json:"minor-dec-ratio"` // only for v1
SrcToleranceRatio float64 `json:"src-tolerance-ratio"`
DstToleranceRatio float64 `json:"dst-tolerance-ratio"`
ReadPriorities []string `json:"read-priorities"`
ByteRateRankStepRatio float64 `json:"byte-rate-rank-step-ratio"`
KeyRateRankStepRatio float64 `json:"key-rate-rank-step-ratio"`
QueryRateRankStepRatio float64 `json:"query-rate-rank-step-ratio"`
CountRankStepRatio float64 `json:"count-rank-step-ratio"`
GreatDecRatio float64 `json:"great-dec-ratio"`
MinorDecRatio float64 `json:"minor-dec-ratio"` // only for v1

// If SrcToleranceRatio and DstToleranceRatio are zero,
// it means hot region scheduler will not consider about expectation and variance.
SrcToleranceRatio float64 `json:"src-tolerance-ratio"`
DstToleranceRatio float64 `json:"dst-tolerance-ratio"`

// For first priority of write leader, it is better to consider key rate or query rather than byte
WriteLeaderPriorities []string `json:"write-leader-priorities"`
WritePeerPriorities []string `json:"write-peer-priorities"`
StrictPickingStore bool `json:"strict-picking-store,string"` // only for v1
ReadPriorities []string `json:"read-priorities"`

StrictPickingStore bool `json:"strict-picking-store,string"` // only for v1

// Separately control whether to start hotspot scheduling for TiFlash
EnableForTiFlash bool `json:"enable-for-tiflash,string"`
Expand Down
4 changes: 2 additions & 2 deletions server/schedulers/hot_region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1978,8 +1978,8 @@ func TestHotScheduleWithStddev(t *testing.T) {
opt := config.NewTestOptions()
hb, err := schedule.CreateScheduler(statistics.Write.String(), schedule.NewOperatorController(ctx, nil, nil), storage.NewStorageWithMemoryBackend(), nil)
re.NoError(err)
hb.(*hotScheduler).conf.SetDstToleranceRatio(0.0)
hb.(*hotScheduler).conf.SetSrcToleranceRatio(0.0)
hb.(*hotScheduler).conf.SetDstToleranceRatio(1.0)
hb.(*hotScheduler).conf.SetSrcToleranceRatio(1.0)
tc := mockcluster.NewCluster(ctx, opt)
tc.SetClusterVersion(versioninfo.MinSupportedVersion(versioninfo.Version4_0))
tc.SetHotRegionCacheHitsThreshold(0)
Expand Down
3 changes: 3 additions & 0 deletions server/schedulers/hot_region_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func (bs *balanceSolver) pickCheckPolicyV2() {
}

func (bs *balanceSolver) filterUniformStoreV2() (string, bool) {
if !bs.enableExpectation() {
return "", false
}
// Because region is available for src and dst, so stddev is the same for both, only need to calcurate one.
isUniformFirstPriority, isUniformSecondPriority := bs.isUniformFirstPriority(bs.cur.srcStore), bs.isUniformSecondPriority(bs.cur.srcStore)
if isUniformFirstPriority && isUniformSecondPriority {
Expand Down

0 comments on commit 85ace3d

Please sign in to comment.