From efcc8bf08254ef12280b7fa3d2ab629d003eebae Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Tue, 10 Aug 2021 17:06:18 -0400 Subject: [PATCH] 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! --- .changelog/11005.txt | 4 ++++ client/client.go | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changelog/11005.txt diff --git a/.changelog/11005.txt b/.changelog/11005.txt new file mode 100644 index 000000000..f9874d760 --- /dev/null +++ b/.changelog/11005.txt @@ -0,0 +1,4 @@ + +```release-note:improvement +client: Speed up client startup time +``` diff --git a/client/client.go b/client/client.go index 2442bdb22..e259b4376 100644 --- a/client/client.go +++ b/client/client.go @@ -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 }