server: compute backoff with connection duration relaxation
This commit is contained in:
parent
60edca164c
commit
a704c67791
28
server.go
28
server.go
@ -2011,7 +2011,7 @@ func (s *server) peerTerminationWatcher(p *peer) {
|
|||||||
s.persistentConnReqs[pubStr], connReq)
|
s.persistentConnReqs[pubStr], connReq)
|
||||||
|
|
||||||
// Record the computed backoff in the backoff map.
|
// Record the computed backoff in the backoff map.
|
||||||
backoff := s.nextPeerBackoff(pubStr)
|
backoff := s.nextPeerBackoff(pubStr, p.StartTime())
|
||||||
s.persistentPeersBackoff[pubStr] = backoff
|
s.persistentPeersBackoff[pubStr] = backoff
|
||||||
|
|
||||||
// Initialize a retry canceller for this peer if one does not
|
// Initialize a retry canceller for this peer if one does not
|
||||||
@ -2048,7 +2048,9 @@ func (s *server) peerTerminationWatcher(p *peer) {
|
|||||||
// nextPeerBackoff computes the next backoff duration for a peer's pubkey using
|
// nextPeerBackoff computes the next backoff duration for a peer's pubkey using
|
||||||
// exponential backoff. If no previous backoff was known, the default is
|
// exponential backoff. If no previous backoff was known, the default is
|
||||||
// returned.
|
// returned.
|
||||||
func (s *server) nextPeerBackoff(pubStr string) time.Duration {
|
func (s *server) nextPeerBackoff(pubStr string,
|
||||||
|
startTime time.Time) time.Duration {
|
||||||
|
|
||||||
// Now, determine the appropriate backoff to use for the retry.
|
// Now, determine the appropriate backoff to use for the retry.
|
||||||
backoff, ok := s.persistentPeersBackoff[pubStr]
|
backoff, ok := s.persistentPeersBackoff[pubStr]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -2056,11 +2058,29 @@ func (s *server) nextPeerBackoff(pubStr string) time.Duration {
|
|||||||
return defaultBackoff
|
return defaultBackoff
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, use a previous backoff to compute the
|
// If the peer failed to start properly, we'll just use the previous
|
||||||
// subsequent randomized exponential backoff duration.
|
// backoff to compute the subsequent randomized exponential backoff
|
||||||
|
// duration. This will roughly double on average.
|
||||||
|
if startTime.IsZero() {
|
||||||
return computeNextBackoff(backoff)
|
return computeNextBackoff(backoff)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The peer succeeded in starting. We'll reduce the timeout duration
|
||||||
|
// by the length of the connection before applying randomized
|
||||||
|
// exponential backoff. We'll only apply this if:
|
||||||
|
// backoff - connDuration > defaultBackoff
|
||||||
|
connDuration := time.Now().Sub(startTime)
|
||||||
|
relaxedBackoff := backoff - connDuration
|
||||||
|
if relaxedBackoff > defaultBackoff {
|
||||||
|
return computeNextBackoff(relaxedBackoff)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, backoff - connDuration <= defaultBackoff, meaning the
|
||||||
|
// connection lasted much longer than our previous backoff. To reward
|
||||||
|
// such good behavior, we'll reconnect after the default timeout.
|
||||||
|
return defaultBackoff
|
||||||
|
}
|
||||||
|
|
||||||
// shouldRequestGraphSync returns true if the servers deems it necessary that
|
// shouldRequestGraphSync returns true if the servers deems it necessary that
|
||||||
// we sync channel graph state with the remote peer. This method is used to
|
// we sync channel graph state with the remote peer. This method is used to
|
||||||
// avoid _always_ syncing channel graph state with each peer that connects.
|
// avoid _always_ syncing channel graph state with each peer that connects.
|
||||||
|
Loading…
Reference in New Issue
Block a user