Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow throughput samplers to have non-integer rates #74

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion genericsampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestGenericSamplerBehavior(t *testing.T) {
&dynsampler.TotalThroughput{
ClearFrequencyDuration: 1 * time.Second,
GoalThroughputPerSec: 5,
}, []int{1, 3, 9, 27, 81, 243, 729, 2187},
}, []int{1, 4, 14, 43, 129, 388, 1166, 3499},
},
{"WindowedThroughput",
&dynsampler.WindowedThroughput{
Expand Down
4 changes: 2 additions & 2 deletions totalthroughput.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func (t *TotalThroughput) updateMaps() {
}
// figure out our target throughput per key over ClearFrequencyDuration
totalGoalThroughput := float64(t.GoalThroughputPerSec) * t.ClearFrequencyDuration.Seconds()
// floor the throughput but min should be 1 event per bucket per time period
throughputPerKey := int(math.Max(1, totalGoalThroughput/float64(numKeys)))
// split the total throughput equally across the number of keys.
throughputPerKey := float64(totalGoalThroughput) / float64(numKeys)
// for each key, calculate sample rate by dividing counted events by the
// desired number of events
newSavedSampleRates := make(map[string]int)
Expand Down
4 changes: 2 additions & 2 deletions windowedthroughput.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func (t *WindowedThroughput) updateMaps() {
}
// figure out our target throughput per key over the lookback window.
totalGoalThroughput := t.GoalThroughputPerSec * t.LookbackFrequencyDuration.Seconds()
// floor the throughput but min should be 1 event per bucket per time period
throughputPerKey := math.Max(1, float64(totalGoalThroughput)/float64(numKeys))
// split the total throughput equally across the number of keys.
throughputPerKey := float64(totalGoalThroughput) / float64(numKeys)
// for each key, calculate sample rate by dividing counted events by the
// desired number of events
newSavedSampleRates := make(map[string]int)
Expand Down