server: add an exponential back off to initialPeerBootstrap
In this commit we add exponential back off to the `initialPeerBootstrap` method. Before this change, if the DNS seed was down, we would hammer it in an attempt to get our initial set of peers. This makes this section a bit less aggressive, but saves log spam and also will hit the DNS servers less frequently.
This commit is contained in:
parent
efab9cb584
commit
0470d27603
37
server.go
37
server.go
@ -1723,8 +1723,16 @@ const bootstrapBackOffCeiling = time.Minute * 5
|
||||
func (s *server) initialPeerBootstrap(ignore map[autopilot.NodeID]struct{},
|
||||
numTargetPeers uint32, bootstrappers []discovery.NetworkPeerBootstrapper) {
|
||||
|
||||
// We'll start off by waiting 2 seconds between failed attempts, then
|
||||
// double each time we fail until we hit the bootstrapBackOffCeiling.
|
||||
var delaySignal <-chan time.Time
|
||||
delayTime := time.Second * 2
|
||||
|
||||
for {
|
||||
// As want to be more aggressive, we'll use a lower back off celling
|
||||
// then the main peer bootstrap logic.
|
||||
backOffCeiling := bootstrapBackOffCeiling / 5
|
||||
|
||||
for attempts := 0; ; attempts++ {
|
||||
// Check if the server has been requested to shut down in order
|
||||
// to prevent blocking.
|
||||
if s.Stopped() {
|
||||
@ -1741,8 +1749,31 @@ func (s *server) initialPeerBootstrap(ignore map[autopilot.NodeID]struct{},
|
||||
return
|
||||
}
|
||||
|
||||
// Otherwise, we'll request for the remaining number of peers in
|
||||
// order to reach our target.
|
||||
if attempts > 0 {
|
||||
srvrLog.Debugf("Waiting %v before trying to locate "+
|
||||
"bootstrap peers (attempt #%v)", delayTime,
|
||||
attempts)
|
||||
|
||||
// We've completed at least one iterating and haven't
|
||||
// finished, so we'll start to insert a delay period
|
||||
// between each attempt.
|
||||
delaySignal = time.After(delayTime)
|
||||
select {
|
||||
case <-delaySignal:
|
||||
case <-s.quit:
|
||||
return
|
||||
}
|
||||
|
||||
// After our delay, we'll double the time we wait up to
|
||||
// the max back off period.
|
||||
delayTime *= 2
|
||||
if delayTime > backOffCeiling {
|
||||
delayTime = backOffCeiling
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, we'll request for the remaining number of peers
|
||||
// in order to reach our target.
|
||||
peersNeeded := numTargetPeers - numActivePeers
|
||||
bootstrapAddrs, err := discovery.MultiSourceBootstrap(
|
||||
ignore, peersNeeded, bootstrappers...,
|
||||
|
Loading…
Reference in New Issue
Block a user