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{}),
|
limits: make(map[string]chan struct{}),
|
||||||
enabled: cfg.Enabled,
|
enabled: cfg.Enabled,
|
||||||
requestThreshold: cfg.Threshold,
|
requestThreshold: cfg.Threshold,
|
||||||
cooloffDuration: time.Duration(cfg.Cooloff) * time.Millisecond,
|
cooloffDuration: time.Duration(cfg.CooloffMS) * time.Millisecond,
|
||||||
}
|
}
|
||||||
if l.enabled {
|
if l.enabled {
|
||||||
go l.clean()
|
go l.clean()
|
||||||
|
|
@ -33,11 +33,11 @@ func newRateLimits(cfg *config.RateLimiting) *rateLimits {
|
||||||
|
|
||||||
func (l *rateLimits) clean() {
|
func (l *rateLimits) clean() {
|
||||||
for {
|
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
|
// lock of the entire map and see if any of the channels are
|
||||||
// empty. If they are then we will close and delete them,
|
// empty. If they are then we will close and delete them,
|
||||||
// freeing up memory.
|
// freeing up memory.
|
||||||
time.Sleep(time.Second * 10)
|
time.Sleep(time.Second * 30)
|
||||||
l.limitsMutex.Lock()
|
l.limitsMutex.Lock()
|
||||||
for k, c := range l.limits {
|
for k, c := range l.limits {
|
||||||
if len(c) == 0 {
|
if len(c) == 0 {
|
||||||
|
|
|
||||||
|
|
@ -106,18 +106,18 @@ type RateLimiting struct {
|
||||||
|
|
||||||
// The cooloff period in milliseconds after a request before the "slot"
|
// The cooloff period in milliseconds after a request before the "slot"
|
||||||
// is freed again
|
// is freed again
|
||||||
Cooloff int64 `yaml:"cooloff_ms"`
|
CooloffMS int64 `yaml:"cooloff_ms"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RateLimiting) Verify(configErrs *ConfigErrors) {
|
func (r *RateLimiting) Verify(configErrs *ConfigErrors) {
|
||||||
if r.Enabled {
|
if r.Enabled {
|
||||||
checkPositive(configErrs, "client_api.rate_limiting.threshold", r.Threshold)
|
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() {
|
func (r *RateLimiting) Defaults() {
|
||||||
r.Enabled = true
|
r.Enabled = true
|
||||||
r.Threshold = 5
|
r.Threshold = 5
|
||||||
r.Cooloff = 500
|
r.CooloffMS = 500
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue