Skip to content

Commit

Permalink
swarm: implement smart dialing logic (#2260)
Browse files Browse the repository at this point in the history
* implement smart dialing

* add more comments and tests

* change address ranking logic to dial one quic address before others

* add randomized worker loop tests

* simplify priority queue implementation

* improve DialRanker docs

* one more test

* add explanatory comments and rename variables

* fix allocations in dialQueue

* fix allocations in dialRanker

* Apply suggestions from code review

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

* fix comments

* add logging

* add holepunching test

* add metrics for tracking dial prioritisation impact

clean up redundant address filtering committed

* add test for webtransport filtering

* update changelog

* fix flaky test

* update dashboard

* update dial ranking delay dashboard to use pie chart

* change <=1ms label to 'No delay' in dashboard

* add defensive check to map presence

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
  • Loading branch information
sukunrt and marten-seemann authored Jun 4, 2023
1 parent 0f9ad8c commit 6f27081
Show file tree
Hide file tree
Showing 15 changed files with 2,127 additions and 270 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Table Of Contents <!-- omit in toc -->
- [v0.28.0](#v0280)
- [v0.27.0](#v0270)
- [v0.26.4](#v0264)
- [v0.26.3](#v0263)
Expand All @@ -8,6 +9,17 @@
- [v0.25.1](#v0251)
- [v0.25.0](#v0250)

# [v0.28.0]()

## 🔦 Highlights <!-- omit in toc -->

### Smart Dialing <!-- omit in toc -->
* When connecting to a peer we now do [happy eyeballs](https://www.rfc-editor.org/rfc/rfc8305) like dial prioritisation to prefer QUIC addresses over TCP addresses. We dial the QUIC address first and wait 250ms to dial the TCP address of the peer.
* In our experiments we've seen little impact on latencies up to 80th percentile. 90th and 95th percentile latencies are impacted. For details see discussion on the [PR](https://github.com/libp2p/go-libp2p/pull/2260#issuecomment-1528848170).
* For details of the address ranking logic see godoc for `swarm.DefaultDialRanker`.
* To disable smart dialing and keep the old behaviour use the
`libp2p.NoDelayNetworkDialRanker` option.

# [v0.27.0](https://github.com/libp2p/go-libp2p/releases/tag/v0.27.0)

### Breaking Changes <!-- omit in toc -->
Expand Down
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ type Config struct {

DisableMetrics bool
PrometheusRegisterer prometheus.Registerer

NoDelayNetworkDialRanker bool
}

func (cfg *Config) makeSwarm(eventBus event.Bus, enableMetrics bool) (*swarm.Swarm, error) {
Expand Down Expand Up @@ -173,6 +175,9 @@ func (cfg *Config) makeSwarm(eventBus event.Bus, enableMetrics bool) (*swarm.Swa
if cfg.MultiaddrResolver != nil {
opts = append(opts, swarm.WithMultiaddrResolver(cfg.MultiaddrResolver))
}
if cfg.NoDelayNetworkDialRanker {
opts = append(opts, swarm.WithNoDialDelay())
}
if enableMetrics {
opts = append(opts,
swarm.WithMetricsTracer(swarm.NewMetricsTracer(swarm.WithRegisterer(cfg.PrometheusRegisterer))))
Expand Down
10 changes: 10 additions & 0 deletions core/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ type Dialer interface {
StopNotify(Notifiee)
}

// AddrDelay provides an address along with the delay after which the address
// should be dialed
type AddrDelay struct {
Addr ma.Multiaddr
Delay time.Duration
}

// DialRanker provides a schedule of dialing the provided addresses
type DialRanker func([]ma.Multiaddr) []AddrDelay

// DedupAddrs deduplicates addresses in place, leave only unique addresses.
// It doesn't allocate.
func DedupAddrs(addrs []ma.Multiaddr) []ma.Multiaddr {
Expand Down
Loading

0 comments on commit 6f27081

Please sign in to comment.