mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
metrics: unexport ewma.Tick method
This commit is contained in:
parent
b1dc19d7ee
commit
4111636841
3 changed files with 13 additions and 13 deletions
|
|
@ -50,22 +50,22 @@ func (a *EWMA) Snapshot() EWMASnapshot {
|
|||
return EWMASnapshot(r)
|
||||
}
|
||||
|
||||
// Tick ticks the clock to update the moving average. It assumes it is called
|
||||
// tick ticks the clock to update the moving average. It assumes it is called
|
||||
// every five seconds.
|
||||
func (a *EWMA) Tick() {
|
||||
func (a *EWMA) tick() {
|
||||
// Optimization to avoid mutex locking in the hot-path.
|
||||
if a.init.Load() {
|
||||
a.updateRate(a.fetchInstantRate())
|
||||
return
|
||||
}
|
||||
// Slow-path: this is only needed on the first Tick() and preserves transactional updating
|
||||
// Slow-path: this is only needed on the first tick() and preserves transactional updating
|
||||
// of init and rate in the else block. The first conditional is needed below because
|
||||
// a different thread could have set a.init = 1 between the time of the first atomic load and when
|
||||
// the lock was acquired.
|
||||
a.mutex.Lock()
|
||||
if a.init.Load() {
|
||||
// The fetchInstantRate() uses atomic loading, which is unnecessary in this critical section
|
||||
// but again, this section is only invoked on the first successful Tick() operation.
|
||||
// but again, this section is only invoked on the first successful tick() operation.
|
||||
a.updateRate(a.fetchInstantRate())
|
||||
} else {
|
||||
a.init.Store(true)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ func BenchmarkEWMA(b *testing.B) {
|
|||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
a.Update(1)
|
||||
a.Tick()
|
||||
a.tick()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ func BenchmarkEWMAParallel(b *testing.B) {
|
|||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
a.Update(1)
|
||||
a.Tick()
|
||||
a.tick()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ func BenchmarkEWMAParallel(b *testing.B) {
|
|||
func TestEWMA1(t *testing.T) {
|
||||
a := NewEWMA1()
|
||||
a.Update(3)
|
||||
a.Tick()
|
||||
a.tick()
|
||||
for i, want := range []float64{0.6,
|
||||
0.22072766470286553, 0.08120116994196772, 0.029872241020718428,
|
||||
0.01098938333324054, 0.004042768199451294, 0.0014872513059998212,
|
||||
|
|
@ -49,7 +49,7 @@ func TestEWMA1(t *testing.T) {
|
|||
func TestEWMA5(t *testing.T) {
|
||||
a := NewEWMA5()
|
||||
a.Update(3)
|
||||
a.Tick()
|
||||
a.tick()
|
||||
for i, want := range []float64{
|
||||
0.6, 0.49123845184678905, 0.4021920276213837, 0.32928698165641596,
|
||||
0.269597378470333, 0.2207276647028654, 0.18071652714732128,
|
||||
|
|
@ -67,7 +67,7 @@ func TestEWMA5(t *testing.T) {
|
|||
func TestEWMA15(t *testing.T) {
|
||||
a := NewEWMA15()
|
||||
a.Update(3)
|
||||
a.Tick()
|
||||
a.tick()
|
||||
for i, want := range []float64{
|
||||
0.6, 0.5613041910189706, 0.5251039914257684, 0.4912384518467888184678905,
|
||||
0.459557003018789, 0.4299187863442732, 0.4021920276213831,
|
||||
|
|
@ -84,6 +84,6 @@ func TestEWMA15(t *testing.T) {
|
|||
|
||||
func elapseMinute(a *EWMA) {
|
||||
for i := 0; i < 12; i++ {
|
||||
a.Tick()
|
||||
a.tick()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,9 +119,9 @@ func (m *Meter) tick() {
|
|||
m.a5.Update(n)
|
||||
m.a15.Update(n)
|
||||
// And trigger them to calculate the rates
|
||||
m.a1.Tick()
|
||||
m.a5.Tick()
|
||||
m.a15.Tick()
|
||||
m.a1.tick()
|
||||
m.a5.tick()
|
||||
m.a15.tick()
|
||||
}
|
||||
|
||||
var arbiter = meterTicker{meters: make(map[*Meter]struct{})}
|
||||
|
|
|
|||
Loading…
Reference in a new issue