Skip to content

Commit 7c4cc03

Browse files
authored
chore: change the max limit to take multiplier of the existing limits (#4263)
1 parent 426d3bf commit 7c4cc03

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

router/throttler/adaptive.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
type adaptiveThrottleConfig struct {
1414
window misc.ValueLoader[time.Duration]
1515
minLimit misc.ValueLoader[int64]
16-
maxLimit misc.ValueLoader[int64]
16+
maxLimit func() int64
1717
}
1818

1919
func (c *adaptiveThrottleConfig) readThrottlingConfig(config *config.Config, destName, destID string) {
@@ -25,16 +25,28 @@ func (c *adaptiveThrottleConfig) readThrottlingConfig(config *config.Config, des
2525
fmt.Sprintf(`Router.throttler.adaptive.%s.%s.minLimit`, destName, destID),
2626
fmt.Sprintf(`Router.throttler.adaptive.%s.minLimit`, destName),
2727
`Router.throttler.adaptive.minLimit`)
28-
c.maxLimit = config.GetReloadableInt64Var(0, 1,
28+
maxLimit := config.GetReloadableInt64Var(0, 1,
2929
fmt.Sprintf(`Router.throttler.adaptive.%s.%s.maxLimit`, destName, destID),
3030
fmt.Sprintf(`Router.throttler.adaptive.%s.maxLimit`, destName),
31-
fmt.Sprintf(`Router.throttler.%s.%s.limit`, destName, destID),
32-
fmt.Sprintf(`Router.throttler.%s.limit`, destName),
3331
`Router.throttler.adaptive.maxLimit`)
32+
limitMultiplier := config.GetReloadableFloat64Var(1.5,
33+
fmt.Sprintf(`Router.throttler.adaptive.%s.%s.limitMultiplier`, destName, destID),
34+
fmt.Sprintf(`Router.throttler.adaptive.%s.limitMultiplier`, destName),
35+
`Router.throttler.adaptive.limitMultiplier`)
36+
limit := config.GetReloadableInt64Var(0, 1,
37+
fmt.Sprintf(`Router.throttler.%s.%s.limit`, destName, destID),
38+
fmt.Sprintf(`Router.throttler.%s.limit`, destName))
39+
c.maxLimit = func() int64 {
40+
maxLimit := maxLimit.Load()
41+
if maxLimit > 0 {
42+
return maxLimit
43+
}
44+
return int64(float64(limit.Load()) * limitMultiplier.Load())
45+
}
3446
}
3547

3648
func (c *adaptiveThrottleConfig) enabled() bool {
37-
return c.minLimit.Load() > 0 && c.maxLimit.Load() > 0 && c.window.Load() > 0 && c.minLimit.Load() <= c.maxLimit.Load()
49+
return c.minLimit.Load() > 0 && c.maxLimit() > 0 && c.window.Load() > 0 && c.minLimit.Load() <= c.maxLimit()
3850
}
3951

4052
type adaptiveThrottler struct {
@@ -72,6 +84,6 @@ func (t *adaptiveThrottler) getLimit() int64 {
7284
if t.limitFactorMeasurement != nil {
7385
t.limitFactorMeasurement.Gauge(limitFactor)
7486
}
75-
limit := int64(float64(t.config.maxLimit.Load()) * limitFactor)
87+
limit := int64(float64(t.config.maxLimit()) * limitFactor)
7688
return max(t.config.minLimit.Load(), limit)
7789
}

0 commit comments

Comments
 (0)