diff --git a/go/vt/vttablet/tabletserver/throttle/throttler.go b/go/vt/vttablet/tabletserver/throttle/throttler.go index 9a576eeb2d6..0aed6bf6075 100644 --- a/go/vt/vttablet/tabletserver/throttle/throttler.go +++ b/go/vt/vttablet/tabletserver/throttle/throttler.go @@ -271,6 +271,9 @@ func NewThrottler(env tabletenv.Env, srvTopoServer srvtopo.Server, ts *topo.Serv throttler.dormantPeriod = dormantPeriod throttler.recentCheckDormantDiff = int64(throttler.dormantPeriod / recentCheckRateLimiterInterval) throttler.recentCheckDiff = int64(1 * time.Second / recentCheckRateLimiterInterval) + if throttler.recentCheckDiff < 1 { + throttler.recentCheckDiff = 1 + } throttler.StoreMetricsThreshold(defaultThrottleLagThreshold.Seconds()) //default throttler.readSelfThrottleMetric = func(ctx context.Context, p *mysql.Probe) *mysql.MySQLThrottleMetric { diff --git a/go/vt/vttablet/tabletserver/throttle/throttler_test.go b/go/vt/vttablet/tabletserver/throttle/throttler_test.go index 41fb944817b..dadd6f59991 100644 --- a/go/vt/vttablet/tabletserver/throttle/throttler_test.go +++ b/go/vt/vttablet/tabletserver/throttle/throttler_test.go @@ -185,6 +185,13 @@ func newTestThrottler() *Throttler { return throttler } +func TestInitThrottler(t *testing.T) { + throttler := newTestThrottler() + assert.Equal(t, 5*time.Second, throttler.dormantPeriod) + assert.EqualValues(t, 5, throttler.recentCheckDormantDiff) + assert.EqualValues(t, 3, throttler.recentCheckDiff) +} + func TestIsAppThrottled(t *testing.T) { throttler := Throttler{ throttledApps: cache.New(cache.NoExpiration, 0),