Skip to content

Commit

Permalink
core: clean some remain code about deviation filter. (#5329)
Browse files Browse the repository at this point in the history
close #5328

Signed-off-by: bufferflies <[email protected]>
  • Loading branch information
bufferflies authored Jul 22, 2022
1 parent 30732c1 commit 97be557
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 31 deletions.
28 changes: 2 additions & 26 deletions server/core/store_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package core

import (
"math"

"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/tikv/pd/pkg/movingaverage"
"github.com/tikv/pd/pkg/syncutil"
Expand All @@ -28,20 +26,12 @@ type storeStats struct {

// avgAvailable is used to make available smooth, aka no sudden changes.
avgAvailable *movingaverage.HMA
// Following two fields are used to trace the deviation when available
// records' deviation range to make scheduling able to converge.
// Here `MaxFilter` is used to make the scheduling more conservative, and
// `HMA` is used to make it smooth.
maxAvailableDeviation *movingaverage.MaxFilter
avgMaxAvailableDeviation *movingaverage.HMA
}

func newStoreStats() *storeStats {
return &storeStats{
rawStats: &pdpb.StoreStats{},
avgAvailable: movingaverage.NewHMA(60), // take 10 minutes sample under 10s heartbeat rate
maxAvailableDeviation: movingaverage.NewMaxFilter(120), // take 20 minutes sample under 10s heartbeat rate
avgMaxAvailableDeviation: movingaverage.NewHMA(60), // take 10 minutes sample under 10s heartbeat rate
rawStats: &pdpb.StoreStats{},
avgAvailable: movingaverage.NewHMA(60), // take 10 minutes sample under 10s heartbeat rate
}
}

Expand All @@ -53,11 +43,7 @@ func (ss *storeStats) updateRawStats(rawStats *pdpb.StoreStats) {
if ss.avgAvailable == nil {
return
}

ss.avgAvailable.Add(float64(rawStats.GetAvailable()))
deviation := math.Abs(float64(rawStats.GetAvailable()) - ss.avgAvailable.Get())
ss.maxAvailableDeviation.Add(deviation)
ss.avgMaxAvailableDeviation.Add(ss.maxAvailableDeviation.Get())
}

// GetStoreStats returns the statistics information of the store.
Expand Down Expand Up @@ -157,16 +143,6 @@ func (ss *storeStats) GetAvgAvailable() uint64 {
return climp0(ss.avgAvailable.Get())
}

// GetAvailableDeviation returns approximate magnitude of available in the recent period.
func (ss *storeStats) GetAvailableDeviation() uint64 {
ss.mu.RLock()
defer ss.mu.RUnlock()
if ss.avgMaxAvailableDeviation == nil {
return 0
}
return climp0(ss.avgMaxAvailableDeviation.Get())
}

func climp0(v float64) uint64 {
if v <= 0 {
return 0
Expand Down
3 changes: 0 additions & 3 deletions server/core/store_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func TestStoreStats(t *testing.T) {
re.Equal(uint64(50*units.GiB), store.GetUsedSize())
re.Equal(uint64(150*units.GiB), store.GetAvailable())
re.Equal(uint64(150*units.GiB), store.GetAvgAvailable())
re.Equal(uint64(0), store.GetAvailableDeviation())

store = store.Clone(SetStoreStats(&pdpb.StoreStats{
Capacity: uint64(200 * units.GiB),
Expand All @@ -47,6 +46,4 @@ func TestStoreStats(t *testing.T) {
re.Equal(uint64(160*units.GiB), store.GetAvailable())
re.Greater(store.GetAvgAvailable(), uint64(150*units.GiB))
re.Less(store.GetAvgAvailable(), uint64(160*units.GiB))
re.Greater(store.GetAvailableDeviation(), uint64(0))
re.Less(store.GetAvailableDeviation(), uint64(10*units.GiB))
}
2 changes: 0 additions & 2 deletions server/statistics/store_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ func (s *storeStatistics) Observe(store *core.StoreInfo, stats *StoresStats) {
storeStatusGauge.WithLabelValues(storeAddress, id, "store_available").Set(float64(store.GetAvailable()))
storeStatusGauge.WithLabelValues(storeAddress, id, "store_used").Set(float64(store.GetUsedSize()))
storeStatusGauge.WithLabelValues(storeAddress, id, "store_capacity").Set(float64(store.GetCapacity()))
storeStatusGauge.WithLabelValues(storeAddress, id, "store_available_avg").Set(float64(store.GetAvgAvailable()))
storeStatusGauge.WithLabelValues(storeAddress, id, "store_available_deviation").Set(float64(store.GetAvailableDeviation()))

// Store flows.
storeFlowStats := stats.GetRollingStoreStats(store.GetID())
Expand Down

0 comments on commit 97be557

Please sign in to comment.