Replace time-dependent cache limiting with LRU

To keep memory usage as constant as possible, the previous cache
purging at periodic time intervals has been replaced by an LRU that
discards the oldest string when the capacity of the cache is reached.

Also fixed some formatting and commenting issues, and added better
testing for the rate limiter.

Signed-off-by: Wendi Yu <wendi.yu@yahoo.ca>
This commit is contained in:
Wendi Yu
2020-05-07 13:54:45 -06:00
parent ca6675386b
commit 8a94ccc5a2
5 changed files with 84 additions and 52 deletions

View File

@@ -51,8 +51,8 @@ func main() {
statepath := getopt.StringLong("state", 0, paths.DefaultTailscaledStateFile(), "Path of state file")
socketpath := getopt.StringLong("socket", 's', paths.DefaultTailscaledSocket(), "Path of the service unix socket")
rlPrint := logger.RateLimitedFn(log.Printf, 1, 1)
logf := wgengine.RusagePrefixLog(rlPrint)
logf := wgengine.RusagePrefixLog(log.Printf)
logf = logger.RateLimitedFn(logf, 1, 1, 100)
err := fixconsole.FixConsoleIfNeeded()
if err != nil {