@@ -13,7 +13,7 @@ import (
13
13
type adaptiveThrottleConfig struct {
14
14
window misc.ValueLoader [time.Duration ]
15
15
minLimit misc.ValueLoader [int64 ]
16
- maxLimit misc. ValueLoader [ int64 ]
16
+ maxLimit func () int64
17
17
}
18
18
19
19
func (c * adaptiveThrottleConfig ) readThrottlingConfig (config * config.Config , destName , destID string ) {
@@ -25,16 +25,28 @@ func (c *adaptiveThrottleConfig) readThrottlingConfig(config *config.Config, des
25
25
fmt .Sprintf (`Router.throttler.adaptive.%s.%s.minLimit` , destName , destID ),
26
26
fmt .Sprintf (`Router.throttler.adaptive.%s.minLimit` , destName ),
27
27
`Router.throttler.adaptive.minLimit` )
28
- c . maxLimit = config .GetReloadableInt64Var (0 , 1 ,
28
+ maxLimit : = config .GetReloadableInt64Var (0 , 1 ,
29
29
fmt .Sprintf (`Router.throttler.adaptive.%s.%s.maxLimit` , destName , destID ),
30
30
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 ),
33
31
`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
+ }
34
46
}
35
47
36
48
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 ()
38
50
}
39
51
40
52
type adaptiveThrottler struct {
@@ -72,6 +84,6 @@ func (t *adaptiveThrottler) getLimit() int64 {
72
84
if t .limitFactorMeasurement != nil {
73
85
t .limitFactorMeasurement .Gauge (limitFactor )
74
86
}
75
- limit := int64 (float64 (t .config .maxLimit . Load ()) * limitFactor )
87
+ limit := int64 (float64 (t .config .maxLimit ()) * limitFactor )
76
88
return max (t .config .minLimit .Load (), limit )
77
89
}
0 commit comments