wgengine/magicsock: add hysteresis to endpoint selection

Avoid selecting an endpoint as "better" than the current endpoint if the
total latency improvement is less than 1%. This adds some hysteresis to
avoid flapping between endpoints for a minimal improvement in latency.

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: If8312e1768ea65c4b4d4e13d8de284b3825d7a73
This commit is contained in:
Andrew Dunham
2023-04-21 11:35:16 -04:00
parent c5bf868940
commit bcf7b63d7e
2 changed files with 27 additions and 1 deletions
+5 -1
View File
@@ -1633,9 +1633,13 @@ func TestBetterAddr(t *testing.T) {
{a: zero, b: zero, want: false},
{a: al("10.0.0.2:123", 5*ms), b: zero, want: true},
{a: zero, b: al("10.0.0.2:123", 5*ms), want: false},
{a: al("10.0.0.2:123", 5*ms), b: al("1.2.3.4:555", 6*ms), want: true},
{a: al("10.0.0.2:123", 5*ms), b: al("1.2.3.4:555", 10*ms), want: true},
{a: al("10.0.0.2:123", 5*ms), b: al("10.0.0.2:123", 10*ms), want: false}, // same IPPort
// Don't prefer b to a if it's not substantially better.
{a: al("10.0.0.2:123", 100*ms), b: al("1.2.3.4:555", 101*ms), want: false},
{a: al("10.0.0.2:123", 100*ms), b: al("1.2.3.4:555", 103*ms), want: true},
// Prefer IPv6 if roughly equivalent:
{
a: al("[2001::5]:123", 100*ms),