diff --git a/server/config.go b/server/config.go index cf1b6916847f..54085af6f0f2 100644 --- a/server/config.go +++ b/server/config.go @@ -353,15 +353,15 @@ type ScheduleConfig struct { // TolerantSizeRatio is the ratio of buffer size for balance scheduler. TolerantSizeRatio float64 `toml:"tolerant-size-ratio,omitempty" json:"tolerant-size-ratio"` // - // high space stage transition stage low space stage + // high space stage transition stage low space stage // |--------------------|-----------------------------|-------------------------| // ^ ^ ^ ^ - // 0 (1 - LowSpaceRatio) * capacity (1 - SpaceRatio) * capacity capacity + // 0 HighSpaceRatio * capacity LowSpaceRatio * capacity capacity // - // LowSpaceRatio is the lowest available ratio of store which regraded as low space. + // LowSpaceRatio is the lowest usage ratio of store which regraded as low space. // When in low space, store region score increases to very large and varies inversely with available size. LowSpaceRatio float64 `toml:"low-space-ratio,omitempty" json:"low-space-ratio"` - // HighSpaceRatio is the highest available ratio of store which regraded as high space. + // HighSpaceRatio is the highest usage ratio of store which regraded as high space. // High space means there is a lot of spare capacity, and store region score varies directly with used size. HighSpaceRatio float64 `toml:"high-space-ratio,omitempty" json:"high-space-ratio"` // EnableRaftLearner is the option for using AddLearnerNode instead of AddNode @@ -410,9 +410,9 @@ const ( defaultRegionScheduleLimit = 4 defaultReplicaScheduleLimit = 8 defaultMergeScheduleLimit = 8 - defaultTolerantSizeRatio = 2.5 - defaultLowSpaceRatio = 0.2 - defaultHighSpaceRatio = 0.5 + defaultTolerantSizeRatio = 5 + defaultLowSpaceRatio = 0.8 + defaultHighSpaceRatio = 0.6 ) var defaultSchedulers = SchedulerConfigs{ diff --git a/server/core/store.go b/server/core/store.go index 47ace78b43d7..8d51bebdcbdf 100644 --- a/server/core/store.go +++ b/server/core/store.go @@ -122,17 +122,12 @@ func (s *StoreInfo) RegionScore(highSpaceRatio, lowSpaceRatio float64, delta int var score float64 - // lowSpaceRatio shouldn't greater than highSpaceRatio - if lowSpaceRatio > highSpaceRatio { - lowSpaceRatio = highSpaceRatio - } - // because of rocksdb compression, region size is larger than actual used size amplification := float64(s.RegionSize) / (float64(s.Stats.GetUsedSize()) / (1 << 20)) - if available-float64(delta)/amplification >= highSpaceRatio*capacity || lowSpaceRatio < 0 || lowSpaceRatio > 1 { + if available-float64(delta)/amplification >= (1-highSpaceRatio)*capacity { score = float64(s.RegionSize + delta) - } else if available-float64(delta)/amplification <= lowSpaceRatio*capacity || highSpaceRatio < 0 || highSpaceRatio > 1 { + } else if available-float64(delta)/amplification <= (1-lowSpaceRatio)*capacity { score = maxScore - (available - float64(delta)/amplification) } else { // to make the score function continuous, we use linear function y = k * x + b as transition period @@ -140,8 +135,8 @@ func (s *StoreInfo) RegionScore(highSpaceRatio, lowSpaceRatio float64, delta int // p1((1-highSpaceRatio)*capacity*amplification, (1-highSpaceRatio)*capacity*amplification) and // p2((1-lowSpaceRatio)*capacity*amplification, maxScore-lowSpaceRatio*capacity) // so k = (y2 - y1) / (x2 - x1) - x1, y1 := (1-highSpaceRatio)*capacity*amplification, (1-highSpaceRatio)*capacity*amplification - x2, y2 := (1-lowSpaceRatio)*capacity*amplification, maxScore-lowSpaceRatio*capacity + x1, y1 := highSpaceRatio*capacity*amplification, highSpaceRatio*capacity*amplification + x2, y2 := lowSpaceRatio*capacity*amplification, maxScore-(1-lowSpaceRatio)*capacity k := (y2 - y1) / (x2 - x1) b := y1 - k*x1 diff --git a/server/schedule/mockcluster.go b/server/schedule/mockcluster.go index 796fb7e5df00..b670f755e186 100644 --- a/server/schedule/mockcluster.go +++ b/server/schedule/mockcluster.go @@ -379,9 +379,9 @@ const ( defaultRegionScheduleLimit = 4 defaultReplicaScheduleLimit = 8 defaultMergeScheduleLimit = 8 - defaultTolerantSizeRatio = 2.5 - defaultLowSpaceRatio = 0.2 - defaultHighSpaceRatio = 0.5 + defaultTolerantSizeRatio = 5 + defaultLowSpaceRatio = 0.8 + defaultHighSpaceRatio = 0.6 ) // MockSchedulerOptions is a mock of SchedulerOptions