diff --git a/lib/cluster.go b/lib/cluster.go index 0062c6137..33a7788c7 100644 --- a/lib/cluster.go +++ b/lib/cluster.go @@ -14,6 +14,10 @@ func RandomStagger(intv time.Duration) time.Duration { // order to target an aggregate number of actions per second across the whole // cluster. func RateScaledInterval(rate float64, min time.Duration, n int) time.Duration { + const minRate = 1 / 86400 // 1/(1 * time.Day) + if rate <= minRate { + return min + } interval := time.Duration(float64(time.Second) * float64(n) / rate) if interval < min { return min diff --git a/lib/cluster_test.go b/lib/cluster_test.go index 40949d020..d517e4677 100644 --- a/lib/cluster_test.go +++ b/lib/cluster_test.go @@ -16,7 +16,7 @@ func TestRandomStagger(t *testing.T) { } func TestRateScaledInterval(t *testing.T) { - min := 1 * time.Second + const min = 1 * time.Second rate := 200.0 if v := RateScaledInterval(rate, min, 0); v != min { t.Fatalf("Bad: %v", v) @@ -36,4 +36,13 @@ func TestRateScaledInterval(t *testing.T) { if v := RateScaledInterval(rate, min, 10000); v != 50*time.Second { t.Fatalf("Bad: %v", v) } + if v := RateScaledInterval(0, min, 10000); v != min { + t.Fatalf("Bad: %v", v) + } + if v := RateScaledInterval(0.0, min, 10000); v != min { + t.Fatalf("Bad: %v", v) + } + if v := RateScaledInterval(-1, min, 10000); v != min { + t.Fatalf("Bad: %v", v) + } }