Skip to content

Commit cf1d27f

Browse files
committed
router: budget the per-connection protocols from the connection cap
A member attached elsewhere holds a connection to this router for its DHT queries, with a DHT stream and gossip streams on it like a member's own, and at 10,000 members the testnet's routers carried 9,000 connections each for 3,600 members. The identify, auth, DHT and gossip budgets were sized from the member watermark (6,000), so the gossip streams were refused past it in the last 10k run (327k on one router) and the DHT streams would have been next. They follow the connection cap now, as the connections they ride on do.
1 parent eb641fe commit cf1d27f

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎internal/router/resource_limits.go‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ func hubLimits(highWaterMark, conns, circuits int) rcmgr.ConcreteLimitConfig {
9494
circuit.ProtoIDv2Hop: relayStreams,
9595
circuit.ProtoIDv2Stop: relayStreams,
9696
}
97+
// Every connection, not every member: a member attached elsewhere holds
98+
// a connection here for its DHT queries, with a DHT stream and gossip
99+
// streams on it, and at 10,000 members the testnet's routers carried
100+
// 9,000 connections each for 3,600 members. The connection cap is what
101+
// bounds those streams.
97102
for _, p := range memberProtocols {
98-
protocols[p] = streams(sysBase)
103+
protocols[p] = streams(connCap)
99104
}
100105

101106
overrides := rcmgr.PartialLimitConfig{
@@ -105,7 +110,7 @@ func hubLimits(highWaterMark, conns, circuits int) rcmgr.ConcreteLimitConfig {
105110
// stream per relayed caller, up to the per-peer circuit budget.
106111
PeerDefault: perPeerCircuits,
107112
Service: map[string]rcmgr.ResourceLimits{
108-
identify.ServiceName: streams(sysBase),
113+
identify.ServiceName: streams(connCap),
109114
relay.ServiceName: relayStreams,
110115
},
111116
ServicePeer: map[string]rcmgr.ResourceLimits{

‎internal/router/resource_limits_test.go‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ func TestHubLimitsFollowTheConnectionBudget(t *testing.T) {
4949
want("system inbound streams", cfg.System.StreamsInbound, 8*connCapHeadroom*highWaterMark)
5050
want("transient inbound conns", cfg.Transient.ConnsInbound, highWaterMark)
5151
want("transient inbound streams", cfg.Transient.StreamsInbound, highWaterMark)
52-
want("identify service inbound streams", cfg.Service[identify.ServiceName].StreamsInbound, highWaterMark)
53-
want("identify protocol inbound streams", cfg.Protocol[identify.ID].StreamsInbound, highWaterMark)
54-
want("auth protocol inbound streams", cfg.Protocol[api.AuthProtocolID].StreamsInbound, highWaterMark)
55-
// Every member holds one DHT stream and one gossip stream to its router
56-
// for as long as it is connected; libp2p's default capped them at a few
57-
// hundred in all and the rest of the fleet fell out of discovery.
58-
want("dht protocol inbound streams", cfg.Protocol[api.DHTProtocolID].StreamsInbound, highWaterMark)
52+
want("identify service inbound streams", cfg.Service[identify.ServiceName].StreamsInbound, connCapHeadroom*highWaterMark)
53+
want("identify protocol inbound streams", cfg.Protocol[identify.ID].StreamsInbound, connCapHeadroom*highWaterMark)
54+
want("auth protocol inbound streams", cfg.Protocol[api.AuthProtocolID].StreamsInbound, connCapHeadroom*highWaterMark)
55+
// Every connection holds one DHT stream and one gossip stream for as
56+
// long as it lasts, and a router carries connections from members
57+
// attached elsewhere as well as its own, so these follow the connection
58+
// cap; libp2p's default capped them at a few hundred in all and the rest
59+
// of the fleet fell out of discovery.
60+
want("dht protocol inbound streams", cfg.Protocol[api.DHTProtocolID].StreamsInbound, connCapHeadroom*highWaterMark)
5961
for _, p := range pubsub.GossipSubDefaultProtocols {
60-
want("gossip protocol "+string(p)+" inbound streams", cfg.Protocol[p].StreamsInbound, highWaterMark)
62+
want("gossip protocol "+string(p)+" inbound streams", cfg.Protocol[p].StreamsInbound, connCapHeadroom*highWaterMark)
6163
}
6264
want("relay service inbound streams", cfg.Service[relay.ServiceName].StreamsInbound, highWaterMark)
6365
// yamux reserves one window per open stream through the manager, so

0 commit comments

Comments
 (0)