Skip to content

Commit

Permalink
core: adjust capacity to fit for more cases (tikv#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor1996 authored and disksing committed May 7, 2018
1 parent 47a5022 commit 0756358
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
2 changes: 0 additions & 2 deletions conf/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 21 additions & 14 deletions server/core/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions server/store_statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 0756358

Please sign in to comment.