From 584d56185468846d4d3c6b543fea1cacf02a16ee Mon Sep 17 00:00:00 2001 From: Connor1996 Date: Thu, 19 Apr 2018 16:35:41 +0800 Subject: [PATCH 1/5] adjust capacity --- server/core/store.go | 15 ++++++++------- server/store_statistics.go | 6 ++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/server/core/store.go b/server/core/store.go index b40005b2368..ce23d5e749c 100644 --- a/server/core/store.go +++ b/server/core/store.go @@ -114,16 +114,16 @@ 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) + return float64(delta) / math.Max(s.RegionWeight, minWeight) } - capacity := float64(s.Stats.GetCapacity()) / (1 << 20) - available := float64(s.Stats.GetAvailable()) / (1 << 20) - var score float64 + available := float64(s.Stats.GetAvailable()) / (1 << 20) + used := float64(s.Stats.GetUsedSize()) / (1 << 20) + capacity := available + used // because of rocksdb compression, region size is larger than actual used size - amplification := float64(s.RegionSize) / (float64(s.Stats.GetUsedSize()) / (1 << 20)) + amplification := float64(s.RegionSize) / used if available-float64(delta)/amplification >= (1-highSpaceRatio)*capacity { score = float64(s.RegionSize + delta) @@ -153,10 +153,11 @@ func (s *StoreInfo) StorageSize() uint64 { // AvailableRatio is store's freeSpace/capacity. func (s *StoreInfo) AvailableRatio() float64 { - if s.Stats.GetCapacity() == 0 { + capacity := float64(s.Stats.GetUsedSize()) + float64(s.Stats.GetAvailable()) + if capacity == 0 { return 0 } - return float64(s.Stats.GetAvailable()) / float64(s.Stats.GetCapacity()) + return float64(s.Stats.GetAvailable()) / capacity } // IsLowSpace checks if the store is lack of space. diff --git a/server/store_statistics.go b/server/store_statistics.go index ce5e3c7409f..d571fcf8684 100644 --- a/server/store_statistics.go +++ b/server/store_statistics.go @@ -80,10 +80,8 @@ 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())) } func (s *storeStatistics) Collect() { From 73a03ec68e94ba2e1f8fa04bdc4a932cee1e968d Mon Sep 17 00:00:00 2001 From: Connor1996 Date: Thu, 19 Apr 2018 18:13:36 +0800 Subject: [PATCH 2/5] consider irrelative size --- server/core/store.go | 23 ++++++++++++++--------- server/store_statistics.go | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/server/core/store.go b/server/core/store.go index ce23d5e749c..da64e6ea3c2 100644 --- a/server/core/store.go +++ b/server/core/store.go @@ -120,7 +120,7 @@ func (s *StoreInfo) RegionScore(highSpaceRatio, lowSpaceRatio float64, delta int var score float64 available := float64(s.Stats.GetAvailable()) / (1 << 20) used := float64(s.Stats.GetUsedSize()) / (1 << 20) - capacity := available + used + capacity := float64(s.Stats.GetCapacity()) / (1 << 20) // because of rocksdb compression, region size is larger than actual used size amplification := float64(s.RegionSize) / used @@ -132,11 +132,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 @@ -153,11 +159,10 @@ func (s *StoreInfo) StorageSize() uint64 { // AvailableRatio is store's freeSpace/capacity. func (s *StoreInfo) AvailableRatio() float64 { - capacity := float64(s.Stats.GetUsedSize()) + float64(s.Stats.GetAvailable()) - if capacity == 0 { + if float64(s.Stats.GetCapacity()) == 0 { return 0 } - return float64(s.Stats.GetAvailable()) / capacity + return float64(s.Stats.GetAvailable()) / float64(s.Stats.GetCapacity()) } // IsLowSpace checks if the store is lack of space. diff --git a/server/store_statistics.go b/server/store_statistics.go index d571fcf8684..08f46c254cb 100644 --- a/server/store_statistics.go +++ b/server/store_statistics.go @@ -82,6 +82,7 @@ func (s *storeStatistics) Observe(store *core.StoreInfo) { storeStatusGauge.WithLabelValues(s.namespace, id, "leader_count").Set(float64(store.LeaderCount)) 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() { From 4915cab078f1841cda5f3f14793ed4ab6001c562 Mon Sep 17 00:00:00 2001 From: Connor1996 Date: Thu, 19 Apr 2018 18:16:12 +0800 Subject: [PATCH 3/5] tiny clean up --- server/core/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/core/store.go b/server/core/store.go index da64e6ea3c2..62598e46888 100644 --- a/server/core/store.go +++ b/server/core/store.go @@ -159,7 +159,7 @@ func (s *StoreInfo) StorageSize() uint64 { // AvailableRatio is store's freeSpace/capacity. func (s *StoreInfo) AvailableRatio() float64 { - if float64(s.Stats.GetCapacity()) == 0 { + if s.Stats.GetCapacity() == 0 { return 0 } return float64(s.Stats.GetAvailable()) / float64(s.Stats.GetCapacity()) From 5af71e69e8bbbbe524567555cd73c5c65a63608a Mon Sep 17 00:00:00 2001 From: Connor1996 Date: Thu, 19 Apr 2018 19:31:12 +0800 Subject: [PATCH 4/5] fix typo --- conf/config.toml | 2 -- 1 file changed, 2 deletions(-) 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 From 1608daf7ff0ad7e7eada844b94b0c48bc415187c Mon Sep 17 00:00:00 2001 From: Connor1996 Date: Fri, 20 Apr 2018 11:15:51 +0800 Subject: [PATCH 5/5] fix unstable when size is zero --- server/core/store.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/server/core/store.go b/server/core/store.go index 62598e46888..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) / math.Max(s.RegionWeight, minWeight) - } - 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) / used + 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)