zebra icon indicating copy to clipboard operation
zebra copied to clipboard

Prefer faster peers, but if all peers are slow, still connect to them

Open teor2345 opened this issue 2 years ago • 0 comments

Motivation

In PR #4212, we reduced the peer handshake timeout from 4 to 3 seconds, to speed up full sync. But this could cause connection issues on slower networks.

Instead, we want to:

  • prefer faster peers,
  • but remove the fixed peer handshake timeout, so that Zebra still works on slow networks.

We don't need to do this until it actually becomes a problem for users.

Alternative Designs

Disconnect Slow Peers

Related Work

We might also want to prefer faster peers to slower peers, to improve sync speeds. This could use a similar algorithm: during the initial sync, every minute, disconnect the peer with the slowest round-trip time. (1.6 - 5 times the peer set size during a 6 hour initial sync.)

Additive Increase, Multiplicative Decrease

We could use a dynamic peer connection timeout, with an additive-decrease-multiplicative-increase algorithm.

Every minute:

  • if we're at the connection limit, reduce the peer timeout by 1 second
  • if we have less than the initial connection target, double the peer timeout

We only want to count connections that have successful handshakes. We'd need to limit the range of the timeout to 1..=request timeout.

teor2345 avatar Apr 28 '22 02:04 teor2345