From d76d33ac3cc32caa3841bc2459ff2429c7dee4f8 Mon Sep 17 00:00:00 2001 From: Kent Quirk Date: Thu, 11 Jan 2024 22:16:59 -0500 Subject: [PATCH 1/2] Resolve conflict from #69 --- totalthroughput.go | 4 ++-- windowedthroughput.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/totalthroughput.go b/totalthroughput.go index 2f9bdb3..862c566 100644 --- a/totalthroughput.go +++ b/totalthroughput.go @@ -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) diff --git a/windowedthroughput.go b/windowedthroughput.go index a79bd77..983821d 100644 --- a/windowedthroughput.go +++ b/windowedthroughput.go @@ -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) From 4a1981fdca507c82e28bc76e175a5bb6d31c8009 Mon Sep 17 00:00:00 2001 From: fchikwekwe Date: Fri, 12 Jan 2024 14:55:57 -0500 Subject: [PATCH 2/2] fix: update throughput test to use new math --- genericsampler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genericsampler_test.go b/genericsampler_test.go index 2c1294b..2ac7aae 100644 --- a/genericsampler_test.go +++ b/genericsampler_test.go @@ -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{