mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-22 12:58:37 +00:00
Remove unnecessary cache copying in ratelimiting
Signed-off-by: Wendi Yu <wendi.yu@yahoo.ca>
This commit is contained in:
parent
8a94ccc5a2
commit
ac5039ab39
@ -196,12 +196,12 @@ func newNode(t *testing.T, prefix string, https *httptest.Server, weirdPrefs boo
|
||||
logfe := func(fmt string, args ...interface{}) {
|
||||
t.Logf(prefix+".e: "+fmt, args...)
|
||||
}
|
||||
logfe := logger.RateLimitedFn(logfe, 1, 1)
|
||||
logfe = logger.RateLimitedFn(logfe, 1, 1, 100)
|
||||
|
||||
logf := func(fmt string, args ...interface{}) {
|
||||
t.Logf(prefix+": "+fmt, args...)
|
||||
}
|
||||
logf := logger.RateLimitedFn(logf, 1, 1, 100)
|
||||
logf = logger.RateLimitedFn(logf, 1, 1, 100)
|
||||
|
||||
var err error
|
||||
httpc := https.Client()
|
||||
|
@ -95,20 +95,9 @@ func RateLimitedFn(logf Logf, f float64, b int, m int) Logf {
|
||||
|
||||
mu.Lock()
|
||||
if msgCache.Len() > m {
|
||||
delete(msgLim, msgCache.Back().Value.(string))
|
||||
msgCache.Remove(msgCache.Back())
|
||||
}
|
||||
|
||||
// Purge msgLim of outdated keys to reduce overhead. Must be done by copying
|
||||
// over to a new map and allowing the garbage collector to eat the entire old one,
|
||||
// since deleting keys in maps is done through a "zombie flag" on the data rather than
|
||||
// actually clearing it from memory. See https://github.com/golang/go/issues/20135
|
||||
if len(msgLim)-msgCache.Len() > 100 {
|
||||
newList := make(map[string]*limitData)
|
||||
for e := msgCache.Front(); e != nil; e = e.Next() {
|
||||
newList[e.Value.(string)] = msgLim[e.Value.(string)]
|
||||
}
|
||||
msgLim = newList
|
||||
}
|
||||
mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user