Skip to content

Commit a52d37d

Browse files
committed
fix: adjust rcmgr limits for accelerated DHT client rt refresh (#8982)
* fix: adjust rcmgr limits for accelerated DHT client rt refresh The Accelerated DHT client periodically refreshes its routing table, including at startup, and if Resource Manager throttling causes the client's routing table to be incomplete, then content routing may be degraded or broken for users. This adjusts the default limits to a level that empirically doesn't cause Resource Manager throttling during initial DHT client bootstrapping. Ideally the Accelerated DHT client would handle this scenario more gracefully, but this works for now to unblock the 0.13 release. * Set default outbound conns unconditionally This also sets the default overall conns as a function of the outbound and inbound conns, since they are adjusted dynamically, and it makes the intention of the value clear. * increase min FD limit (cherry picked from commit b8617b9)
1 parent b58e6fd commit a52d37d

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

core/node/libp2p/rcmgr_defaults.go

+22-9
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,43 @@ func adjustedDefaultLimits(cfg config.SwarmConfig) rcmgr.DefaultLimitConfig {
2525
checkImplicitDefaults()
2626
}
2727

28-
// Return to use unmodified static limits based on values from go-libp2p 0.18
29-
// return defaultLimits
30-
3128
// Adjust limits
3229
// (based on https://github.com/filecoin-project/lotus/pull/8318/files)
3330
// - give it more memory, up to 4G, min of 1G
3431
// - if Swarm.ConnMgr.HighWater is too high, adjust Conn/FD/Stream limits
3532
defaultLimits := rcmgr.DefaultLimits.WithSystemMemory(.125, 1<<30, 4<<30)
3633

34+
// Outbound conns and FDs are set very high to allow for the accelerated DHT client to (re)load its routing table.
35+
// Currently it doesn't gracefully handle RM throttling--once it does we can lower these.
36+
// High outbound conn limits are considered less of a DoS risk than high inbound conn limits.
37+
// Also note that, due to the behavior of the accelerated DHT client, we don't need many streams, just conns.
38+
if minOutbound := 65536; defaultLimits.SystemBaseLimit.ConnsOutbound < minOutbound {
39+
defaultLimits.SystemBaseLimit.ConnsOutbound = minOutbound
40+
}
41+
if minFD := 4096; defaultLimits.SystemBaseLimit.FD < minFD {
42+
defaultLimits.SystemBaseLimit.FD = minFD
43+
}
44+
3745
// Do we need to adjust due to Swarm.ConnMgr.HighWater?
3846
if cfg.ConnMgr.Type == "basic" {
3947
maxconns := cfg.ConnMgr.HighWater
4048
if 2*maxconns > defaultLimits.SystemBaseLimit.ConnsInbound {
41-
// adjust conns to 2x to allow for two conns per peer (TCP+QUIC)
49+
// Conns should be at least 2x larger than the high water to allow for two conns per peer (TCP+QUIC).
4250
defaultLimits.SystemBaseLimit.ConnsInbound = logScale(2 * maxconns)
43-
defaultLimits.SystemBaseLimit.ConnsOutbound = logScale(2 * maxconns)
44-
defaultLimits.SystemBaseLimit.Conns = logScale(4 * maxconns)
4551

46-
defaultLimits.SystemBaseLimit.StreamsInbound = logScale(16 * maxconns)
47-
defaultLimits.SystemBaseLimit.StreamsOutbound = logScale(64 * maxconns)
48-
defaultLimits.SystemBaseLimit.Streams = logScale(64 * maxconns)
52+
// We want the floor of minOutbound conns to be no less than what was set above.
53+
if minOutbound := logScale(2 * maxconns); minOutbound > defaultLimits.SystemBaseLimit.ConnsOutbound {
54+
defaultLimits.SystemBaseLimit.ConnsOutbound = minOutbound
55+
}
4956

5057
if 2*maxconns > defaultLimits.SystemBaseLimit.FD {
5158
defaultLimits.SystemBaseLimit.FD = logScale(2 * maxconns)
5259
}
5360

61+
defaultLimits.SystemBaseLimit.StreamsInbound = logScale(16 * maxconns)
62+
defaultLimits.SystemBaseLimit.StreamsOutbound = logScale(64 * maxconns)
63+
defaultLimits.SystemBaseLimit.Streams = logScale(64 * maxconns)
64+
5465
defaultLimits.ServiceBaseLimit.StreamsInbound = logScale(8 * maxconns)
5566
defaultLimits.ServiceBaseLimit.StreamsOutbound = logScale(32 * maxconns)
5667
defaultLimits.ServiceBaseLimit.Streams = logScale(32 * maxconns)
@@ -61,6 +72,8 @@ func adjustedDefaultLimits(cfg config.SwarmConfig) rcmgr.DefaultLimitConfig {
6172
}
6273
}
6374

75+
defaultLimits.SystemBaseLimit.Conns = defaultLimits.SystemBaseLimit.ConnsOutbound + defaultLimits.SystemBaseLimit.ConnsInbound
76+
6477
return defaultLimits
6578
}
6679

0 commit comments

Comments
 (0)