diff --git a/conf/config.toml b/conf/config.toml index 8f792254f15..3875bdc760f 100644 --- a/conf/config.toml +++ b/conf/config.toml @@ -62,8 +62,6 @@ region-schedule-limit = 4 replica-schedule-limit = 8 merge-schedule-limit = 8 tolerant-size-ratio = 5 -high-space-reatio = 0.8 -low-space-ratio = 0.6 # customized schedulers, the format is as below # if empty, it will use balance-leader, balance-region, hot-region as default diff --git a/server/core/store.go b/server/core/store.go index b40005b2368..82b5f9aa6a8 100644 --- a/server/core/store.go +++ b/server/core/store.go @@ -113,17 +113,18 @@ func (s *StoreInfo) LeaderScore(delta int64) float64 { // RegionScore returns the store's region score. func (s *StoreInfo) RegionScore(highSpaceRatio, lowSpaceRatio float64, delta int64) float64 { - if s.RegionSize == 0 { - return float64(delta) - } - - capacity := float64(s.Stats.GetCapacity()) / (1 << 20) - available := float64(s.Stats.GetAvailable()) / (1 << 20) - var score float64 + var amplification float64 + available := float64(s.Stats.GetAvailable()) / (1 << 20) + used := float64(s.Stats.GetUsedSize()) / (1 << 20) + capacity := float64(s.Stats.GetCapacity()) / (1 << 20) - // because of rocksdb compression, region size is larger than actual used size - amplification := float64(s.RegionSize) / (float64(s.Stats.GetUsedSize()) / (1 << 20)) + if s.RegionSize == 0 { + amplification = 1 + } else { + // because of rocksdb compression, region size is larger than actual used size + amplification = float64(s.RegionSize) / used + } if available-float64(delta)/amplification >= (1-highSpaceRatio)*capacity { score = float64(s.RegionSize + delta) @@ -132,11 +133,17 @@ func (s *StoreInfo) RegionScore(highSpaceRatio, lowSpaceRatio float64, delta int } 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(highSpaceRatio*capacity*amplification, highSpaceRatio*capacity*amplification) and - // p2(lowSpaceRatio*capacity*amplification, maxScore-(1-lowSpaceRatio)*capacity) - // so k = (y2 - y1) / (x2 - x1) - x1, y1 := highSpaceRatio*capacity*amplification, highSpaceRatio*capacity*amplification - x2, y2 := lowSpaceRatio*capacity*amplification, maxScore-(1-lowSpaceRatio)*capacity + // note that it is possible that other irrelative files occupy a lot of storage, so capacity == available + used + irrelative + // and we regarded as irrelative as fixed value. + // Then amp = size / used = size / (capacity - irrelative - available) + // + // when available == (1 - highSpaceRatio) * capacity + // we can conclude that size = (capacity - irrelative - (1 - highSpaceRatio) * capacity) * amp = (used+available-(1-highSpaceRatio)*capacity)*amp + // Similarly, when available == (1 - lowSpaceRatio) * capacity + // we can conclude that size = (capacity - irrelative - (1 - highSpaceRatio) * capacity) * amp = (used+available-(1-lowSpaceRatio)*capacity)*amp + // These are the two fixed points' x-coordinates, and y-coordinates can easily get from the above two functions. + x1, y1 := (used+available-(1-highSpaceRatio)*capacity)*amplification, (used+available-(1-highSpaceRatio)*capacity)*amplification + x2, y2 := (used+available-(1-lowSpaceRatio)*capacity)*amplification, maxScore-(1-lowSpaceRatio)*capacity k := (y2 - y1) / (x2 - x1) b := y1 - k*x1 diff --git a/server/store_statistics.go b/server/store_statistics.go index ce5e3c7409f..08f46c254cb 100644 --- a/server/store_statistics.go +++ b/server/store_statistics.go @@ -80,10 +80,9 @@ func (s *storeStatistics) Observe(store *core.StoreInfo) { storeStatusGauge.WithLabelValues(s.namespace, id, "region_count").Set(float64(store.RegionCount)) storeStatusGauge.WithLabelValues(s.namespace, id, "leader_size").Set(float64(store.LeaderSize)) storeStatusGauge.WithLabelValues(s.namespace, id, "leader_count").Set(float64(store.LeaderCount)) - storeStatusGauge.WithLabelValues(s.namespace, id, "storage_available").Set(float64(store.Stats.GetAvailable())) - storeStatusGauge.WithLabelValues(s.namespace, id, "storage_capacity").Set(float64(store.Stats.GetCapacity())) - storeStatusGauge.WithLabelValues(s.namespace, id, "storage_used").Set(float64(store.Stats.GetUsedSize())) - storeStatusGauge.WithLabelValues(s.namespace, id, "score_amplify").Set(float64(store.RegionSize) / float64(store.Stats.GetUsedSize()) * (1 << 20)) + storeStatusGauge.WithLabelValues(s.namespace, id, "store_available").Set(float64(store.Stats.GetAvailable())) + storeStatusGauge.WithLabelValues(s.namespace, id, "store_used").Set(float64(store.Stats.GetUsedSize())) + storeStatusGauge.WithLabelValues(s.namespace, id, "store_capacity").Set(float64(store.Stats.GetCapacity())) } func (s *storeStatistics) Collect() {