Make startup *way* faster, especially when using DoH
This commit is contained in:
parent
b624f8ef58
commit
26cc68b748
|
@ -84,8 +84,7 @@ func (serversInfo *ServersInfo) registerServer(proxy *Proxy, name string, stamp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (serversInfo *ServersInfo) refreshServer(proxy *Proxy, name string, stamp stamps.ServerStamp) error {
|
func (serversInfo *ServersInfo) refreshServer(proxy *Proxy, name string, stamp stamps.ServerStamp) error {
|
||||||
serversInfo.Lock()
|
serversInfo.RLock()
|
||||||
defer serversInfo.Unlock()
|
|
||||||
previousIndex := -1
|
previousIndex := -1
|
||||||
for i, oldServer := range serversInfo.inner {
|
for i, oldServer := range serversInfo.inner {
|
||||||
if oldServer.Name == name {
|
if oldServer.Name == name {
|
||||||
|
@ -93,6 +92,7 @@ func (serversInfo *ServersInfo) refreshServer(proxy *Proxy, name string, stamp s
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
serversInfo.RUnlock()
|
||||||
newServer, err := serversInfo.fetchServerInfo(proxy, name, stamp, previousIndex < 0)
|
newServer, err := serversInfo.fetchServerInfo(proxy, name, stamp, previousIndex < 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -101,6 +101,15 @@ func (serversInfo *ServersInfo) refreshServer(proxy *Proxy, name string, stamp s
|
||||||
dlog.Fatalf("[%s] != [%s]", name, newServer.Name)
|
dlog.Fatalf("[%s] != [%s]", name, newServer.Name)
|
||||||
}
|
}
|
||||||
newServer.rtt = ewma.NewMovingAverage(RTTEwmaDecay)
|
newServer.rtt = ewma.NewMovingAverage(RTTEwmaDecay)
|
||||||
|
serversInfo.Lock()
|
||||||
|
defer serversInfo.Unlock()
|
||||||
|
previousIndex = -1
|
||||||
|
for i, oldServer := range serversInfo.inner {
|
||||||
|
if oldServer.Name == name {
|
||||||
|
previousIndex = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
if previousIndex >= 0 {
|
if previousIndex >= 0 {
|
||||||
serversInfo.inner[previousIndex] = &newServer
|
serversInfo.inner[previousIndex] = &newServer
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue