fix: go back to the old averaging
All checks were successful
Release Tag / release (push) Successful in 12s
All checks were successful
Release Tag / release (push) Successful in 12s
This commit is contained in:
@@ -8,8 +8,6 @@ import (
|
|||||||
// AvgCacheState is a cache state that averages the last N cache states.
|
// AvgCacheState is a cache state that averages the last N cache states.
|
||||||
type AvgCacheState struct {
|
type AvgCacheState struct {
|
||||||
size int
|
size int
|
||||||
hits int
|
|
||||||
misses int
|
|
||||||
avgs []cachestate.CacheState
|
avgs []cachestate.CacheState
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
@@ -44,21 +42,8 @@ func (a *AvgCacheState) Add(cs cachestate.CacheState) {
|
|||||||
|
|
||||||
a.avgs = append(a.avgs, cs)
|
a.avgs = append(a.avgs, cs)
|
||||||
if len(a.avgs) > a.size {
|
if len(a.avgs) > a.size {
|
||||||
switch a.avgs[0] {
|
|
||||||
case cachestate.CacheStateHit:
|
|
||||||
a.hits--
|
|
||||||
case cachestate.CacheStateMiss:
|
|
||||||
a.misses--
|
|
||||||
}
|
|
||||||
a.avgs = a.avgs[1:]
|
a.avgs = a.avgs[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
switch cs {
|
|
||||||
case cachestate.CacheStateHit:
|
|
||||||
a.hits++
|
|
||||||
case cachestate.CacheStateMiss:
|
|
||||||
a.misses++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avg returns the average cache state.
|
// Avg returns the average cache state.
|
||||||
@@ -66,5 +51,13 @@ func (a *AvgCacheState) Avg() float64 {
|
|||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
|
|
||||||
return float64(a.hits) / (float64(a.misses) + 0.0000001)
|
var hits int
|
||||||
|
|
||||||
|
for _, cs := range a.avgs {
|
||||||
|
if cs == cachestate.CacheStateHit {
|
||||||
|
hits++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return float64(hits) / float64(len(a.avgs))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user