Speed up client startup and registration (#11005)

Speed up client startup, by retrying more until the servers are known.

Currently, if client fingerprinting is fast and finishes before the
client connect to a server, node registration may be delayed by 15
seconds or so!

Ideally, we'd wait until the client discovers the servers and then retry
immediately, but that requires significant code changes.

Here, we simply retry the node registration request every second. That's
basically the equivalent of check if the client discovered servers every
second. Should be a cheap operation.

When testing this change on my local computer and where both servers and
clients are co-located, the time from startup till node registration
dropped from 34 seconds to 8 seconds!
This commit is contained in:
Mahmood Ali 2021-08-10 17:06:18 -04:00 committed by GitHub
parent c1d1906628
commit efcc8bf082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

4
.changelog/11005.txt Normal file
View File

@ -0,0 +1,4 @@
```release-note:improvement
client: Speed up client startup time
```

View File

@ -80,6 +80,10 @@ const (
// devModeRetryIntv is the retry interval used for development
devModeRetryIntv = time.Second
// noServerRetryIntv is the retry interval used when client has not
// connected to server yet
noServerRetryIntv = time.Second
// stateSnapshotIntv is how often the client snapshots state
stateSnapshotIntv = 60 * time.Second
@ -1772,15 +1776,17 @@ func (c *Client) retryRegisterNode() {
return
}
retryIntv := registerRetryIntv
if err == noServersErr {
c.logger.Debug("registration waiting on servers")
c.triggerDiscovery()
retryIntv = noServerRetryIntv
} else {
c.logger.Error("error registering", "error", err)
}
select {
case <-c.rpcRetryWatcher():
case <-time.After(c.retryIntv(registerRetryIntv)):
case <-time.After(c.retryIntv(retryIntv)):
case <-c.shutdownCh:
return
}