Skip to content

Commit

Permalink
reverse space ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor1996 committed Apr 19, 2018
1 parent 562cd4a commit 47c5f69
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
14 changes: 7 additions & 7 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down
13 changes: 4 additions & 9 deletions server/core/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,21 @@ 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
// from above we know that there are two points must on the function image
// 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
Expand Down
6 changes: 3 additions & 3 deletions server/schedule/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 47c5f69

Please sign in to comment.