Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Allow SampleRescaleThreshold to be configured from userspace #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"
)

const rescaleThreshold = time.Hour
var SampleRescaleThreshold = time.Hour

// Samples maintain a statistically-significant selection of values from
// a stream.
Expand Down Expand Up @@ -55,7 +55,7 @@ func NewExpDecaySample(reservoirSize int, alpha float64) Sample {
t0: time.Now(),
values: newExpDecaySampleHeap(reservoirSize),
}
s.t1 = s.t0.Add(rescaleThreshold)
s.t1 = s.t0.Add(SampleRescaleThreshold)
return s
}

Expand All @@ -65,7 +65,7 @@ func (s *ExpDecaySample) Clear() {
defer s.mutex.Unlock()
s.count = 0
s.t0 = time.Now()
s.t1 = s.t0.Add(rescaleThreshold)
s.t1 = s.t0.Add(SampleRescaleThreshold)
s.values.Clear()
}

Expand Down Expand Up @@ -177,7 +177,7 @@ func (s *ExpDecaySample) update(t time.Time, v int64) {
t0 := s.t0
s.values.Clear()
s.t0 = t
s.t1 = s.t0.Add(rescaleThreshold)
s.t1 = s.t0.Add(SampleRescaleThreshold)
for _, v := range values {
v.k = v.k * math.Exp(-s.alpha*s.t0.Sub(t0).Seconds())
s.values.Push(v)
Expand Down