mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 06:43:09 -06:00
Review comments, set cleanup interval to 30 seconds
This commit is contained in:
parent
dd781f666d
commit
a34b83f38e
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue