Skip to content

Commit

Permalink
Speed up client startup and registration (#11005)
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
Mahmood Ali committed Aug 26, 2021
1 parent f8c414b commit a2a4e68
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .changelog/11005.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

```release-note:improvement
client: Speed up client startup time
```
8 changes: 7 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a2a4e68

Please sign in to comment.