Skip to content

Commit 6f27081

Browse files
swarm: implement smart dialing logic (#2260)
* 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>
1 parent 0f9ad8c commit 6f27081

File tree

15 files changed

+2127
-270
lines changed

15 files changed

+2127
-270
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Table Of Contents <!-- omit in toc -->
2+
- [v0.28.0](#v0280)
23
- [v0.27.0](#v0270)
34
- [v0.26.4](#v0264)
45
- [v0.26.3](#v0263)
@@ -8,6 +9,17 @@
89
- [v0.25.1](#v0251)
910
- [v0.25.0](#v0250)
1011

12+
# [v0.28.0]()
13+
14+
## 🔦 Highlights <!-- omit in toc -->
15+
16+
### Smart Dialing <!-- omit in toc -->
17+
* 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.
18+
* 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).
19+
* For details of the address ranking logic see godoc for `swarm.DefaultDialRanker`.
20+
* To disable smart dialing and keep the old behaviour use the
21+
`libp2p.NoDelayNetworkDialRanker` option.
22+
1123
# [v0.27.0](https://github.com/libp2p/go-libp2p/releases/tag/v0.27.0)
1224

1325
### Breaking Changes <!-- omit in toc -->

config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ type Config struct {
123123

124124
DisableMetrics bool
125125
PrometheusRegisterer prometheus.Registerer
126+
127+
NoDelayNetworkDialRanker bool
126128
}
127129

128130
func (cfg *Config) makeSwarm(eventBus event.Bus, enableMetrics bool) (*swarm.Swarm, error) {
@@ -173,6 +175,9 @@ func (cfg *Config) makeSwarm(eventBus event.Bus, enableMetrics bool) (*swarm.Swa
173175
if cfg.MultiaddrResolver != nil {
174176
opts = append(opts, swarm.WithMultiaddrResolver(cfg.MultiaddrResolver))
175177
}
178+
if cfg.NoDelayNetworkDialRanker {
179+
opts = append(opts, swarm.WithNoDialDelay())
180+
}
176181
if enableMetrics {
177182
opts = append(opts,
178183
swarm.WithMetricsTracer(swarm.NewMetricsTracer(swarm.WithRegisterer(cfg.PrometheusRegisterer))))

core/network/network.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ type Dialer interface {
187187
StopNotify(Notifiee)
188188
}
189189

190+
// AddrDelay provides an address along with the delay after which the address
191+
// should be dialed
192+
type AddrDelay struct {
193+
Addr ma.Multiaddr
194+
Delay time.Duration
195+
}
196+
197+
// DialRanker provides a schedule of dialing the provided addresses
198+
type DialRanker func([]ma.Multiaddr) []AddrDelay
199+
190200
// DedupAddrs deduplicates addresses in place, leave only unique addresses.
191201
// It doesn't allocate.
192202
func DedupAddrs(addrs []ma.Multiaddr) []ma.Multiaddr {

0 commit comments

Comments
 (0)