Skip to content

Commit b1ef37e

Browse files
author
c3d1c06c-bf26-477e-b0eb-c50ef4477ba6
authored
improve (stabilize) server rtt computation
prevent sporadic outliers from heavily affecting the server rtt e.g. the new scoring system stops considering the server rtt when it's over 1s: just because a fast server has 2 slow responses in a row shouldn't put it in the bad server category on the other hand this change still allows to adapt to actual slowdowns quite quickly
1 parent d44b0e3 commit b1ef37e

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

dnscrypt-proxy/serversInfo.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
const (
27-
RTTEwmaDecay = 10.0
27+
RTTEwmaDecay = 20.0
2828
)
2929

3030
type RegisteredServer struct {
@@ -1169,9 +1169,20 @@ func (serverInfo *ServerInfo) noticeSuccess(proxy *Proxy) {
11691169
now := time.Now()
11701170
proxy.serversInfo.Lock()
11711171
elapsed := now.Sub(serverInfo.lastActionTS)
1172-
elapsedMs := elapsed.Nanoseconds() / 1000000
1173-
if elapsedMs > 0 && elapsed < proxy.timeout {
1174-
serverInfo.rtt.Add(float64(elapsedMs))
1172+
elapsedMs := float64(elapsed.Nanoseconds() / 1000000)
1173+
if elapsedMs > 0.0 && elapsed < proxy.timeout {
1174+
1175+
// clip extreme elapsedMs value
1176+
avg := serverInfo.rtt.Value()
1177+
if avg <= 0.0 {
1178+
// do nothing
1179+
} else if elapsedMs > 10.0 * avg {
1180+
elapsedMs = 10.0 * avg
1181+
} else if elapsedMs < 0.1 * avg {
1182+
elapsedMs = 0.1 * avg
1183+
}
1184+
1185+
serverInfo.rtt.Add(elapsedMs)
11751186
}
11761187
proxy.serversInfo.Unlock()
11771188
}

0 commit comments

Comments
 (0)