Review comments, set cleanup interval to 30 seconds

This commit is contained in:
Neil Alexander 2020-09-03 09:32:31 +01:00
parent dd781f666d
commit a34b83f38e
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
2 changed files with 6 additions and 6 deletions

View file

@ -23,7 +23,7 @@ func newRateLimits(cfg *config.RateLimiting) *rateLimits {
limits: make(map[string]chan struct{}),
enabled: cfg.Enabled,
requestThreshold: cfg.Threshold,
cooloffDuration: time.Duration(cfg.Cooloff) * time.Millisecond,
cooloffDuration: time.Duration(cfg.CooloffMS) * time.Millisecond,
}
if l.enabled {
go l.clean()
@ -33,11 +33,11 @@ func newRateLimits(cfg *config.RateLimiting) *rateLimits {
func (l *rateLimits) clean() {
for {
// On a ten minute interval, we'll take an exclusive write
// On a 30 second interval, we'll take an exclusive write
// lock of the entire map and see if any of the channels are
// empty. If they are then we will close and delete them,
// freeing up memory.
time.Sleep(time.Second * 10)
time.Sleep(time.Second * 30)
l.limitsMutex.Lock()
for k, c := range l.limits {
if len(c) == 0 {

View file

@ -106,18 +106,18 @@ type RateLimiting struct {
// The cooloff period in milliseconds after a request before the "slot"
// is freed again
Cooloff int64 `yaml:"cooloff_ms"`
CooloffMS int64 `yaml:"cooloff_ms"`
}
func (r *RateLimiting) Verify(configErrs *ConfigErrors) {
if r.Enabled {
checkPositive(configErrs, "client_api.rate_limiting.threshold", r.Threshold)
checkPositive(configErrs, "client_api.rate_limiting.cooloff_ms", r.Cooloff)
checkPositive(configErrs, "client_api.rate_limiting.cooloff_ms", r.CooloffMS)
}
}
func (r *RateLimiting) Defaults() {
r.Enabled = true
r.Threshold = 5
r.Cooloff = 500
r.CooloffMS = 500
}