mirror of
https://github.com/tailscale/tailscale.git
synced 2026-06-06 21:01:11 +08:00
Avoid taking Server.mu for repeated sends from a client to the same small set of local peers. Each sclient now keeps a bounded, goroutine-local LRU of destination public key to clientSet. To cap memory for idle clients, cache entries track a coarsely updated last-used time. The hot path refreshes that timestamp only when it is older than 30 seconds, and incoming ping frames trim entries idle for more than 10 minutes. This keeps cleanup on the client run goroutine without adding another mutex or background goroutine. cmd/derper gets new --peer-cache-max-entries and --peer-cache-max-idle flags. Their zero values use the automatic defaults, and --peer-cache-max-entries=-1 disables the cache. The peer_lookup_cache_misses counter tracks how often lookupDest falls back to the authoritative Server.mu lookup. We do not count hits on the hot path; when the cache is enabled, hits can be derived from packets_received minus peer_lookup_cache_misses. This optimization is pulled out of the larger #13510 DERP flow-tracking work from 2024, which did a bunch more. We can rebase that bigger PR later and discuss its stats and memory impact on its own merits without losing this standalone optimization. The benchmark compares the same code with TS_DEBUG_DERP_DISABLE_PEER_CACHE set true for the before run and the default cached path for the after run: TS_DEBUG_DERP_DISABLE_PEER_CACHE=true go test ./derp/derpserver -run '^$' -bench '^BenchmarkLookupDestPeerCache$' -benchtime=2s -count=10 > before go test ./derp/derpserver -run '^$' -bench '^BenchmarkLookupDestPeerCache$' -benchtime=2s -count=10 > after go run golang.org/x/perf/cmd/benchstat@latest before after goos: linux goarch: amd64 pkg: tailscale.com/derp/derpserver cpu: Intel(R) Xeon(R) 6975P-C │ before │ after │ │ sec/op │ sec/op vs base │ LookupDestPeerCache-16 180.400n ± 0% 5.720n ± 1% -96.83% (p=0.000 n=10) │ before │ after │ │ B/op │ B/op vs base │ LookupDestPeerCache-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ ¹ all samples are equal │ before │ after │ │ allocs/op │ allocs/op vs base │ LookupDestPeerCache-16 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=10) ¹ ¹ all samples are equal Updates #3560 Change-Id: Ie31b540447211fd9415eea6cc235b83a87930093 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> |
||
|---|---|---|
| .. | ||
| addlicense | ||
| build-webclient | ||
| checkmetrics | ||
| cigocacher | ||
| cloner | ||
| connector-gen | ||
| containerboot | ||
| derper | ||
| derpprobe | ||
| dist | ||
| distsign | ||
| featuretags | ||
| get-authkey | ||
| gitops-pusher | ||
| hello | ||
| jsonimports | ||
| k8s-nameserver | ||
| k8s-operator | ||
| k8s-proxy | ||
| mkmanifest | ||
| mkpkg | ||
| mkversion | ||
| nardump | ||
| natc | ||
| netlogfmt | ||
| nginx-auth | ||
| omitsize | ||
| pgproxy | ||
| printdep | ||
| proxy-test-server | ||
| proxy-to-grafana | ||
| sniproxy | ||
| speedtest | ||
| ssh-auth-none-demo | ||
| stunc | ||
| stund | ||
| stunstamp | ||
| sync-containers | ||
| systray | ||
| tailscale | ||
| tailscaled | ||
| testcontrol | ||
| testwrapper | ||
| tl-longchain | ||
| tsconnect | ||
| tsidp | ||
| tsnet-proxy | ||
| tsp | ||
| tsshd | ||
| tta | ||
| vet | ||
| viewer | ||
| vnet | ||
| xdpderper | ||