Skip to content

Commit

Permalink
fix: adjust rcmgr limits for accelerated DHT client rt refresh (#8982)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
guseggert committed Jun 8, 2022
1 parent b58e6fd commit a52d37d
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions core/node/libp2p/rcmgr_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,43 @@ func adjustedDefaultLimits(cfg config.SwarmConfig) rcmgr.DefaultLimitConfig {
checkImplicitDefaults()
}

// Return to use unmodified static limits based on values from go-libp2p 0.18
// return defaultLimits

// Adjust limits
// (based on https://github.com/filecoin-project/lotus/pull/8318/files)
// - give it more memory, up to 4G, min of 1G
// - if Swarm.ConnMgr.HighWater is too high, adjust Conn/FD/Stream limits
defaultLimits := rcmgr.DefaultLimits.WithSystemMemory(.125, 1<<30, 4<<30)

// Outbound conns and FDs are set very high to allow for the accelerated DHT client to (re)load its routing table.
// Currently it doesn't gracefully handle RM throttling--once it does we can lower these.
// High outbound conn limits are considered less of a DoS risk than high inbound conn limits.
// Also note that, due to the behavior of the accelerated DHT client, we don't need many streams, just conns.
if minOutbound := 65536; defaultLimits.SystemBaseLimit.ConnsOutbound < minOutbound {
defaultLimits.SystemBaseLimit.ConnsOutbound = minOutbound
}
if minFD := 4096; defaultLimits.SystemBaseLimit.FD < minFD {
defaultLimits.SystemBaseLimit.FD = minFD
}

// Do we need to adjust due to Swarm.ConnMgr.HighWater?
if cfg.ConnMgr.Type == "basic" {
maxconns := cfg.ConnMgr.HighWater
if 2*maxconns > defaultLimits.SystemBaseLimit.ConnsInbound {
// adjust conns to 2x to allow for two conns per peer (TCP+QUIC)
// Conns should be at least 2x larger than the high water to allow for two conns per peer (TCP+QUIC).
defaultLimits.SystemBaseLimit.ConnsInbound = logScale(2 * maxconns)
defaultLimits.SystemBaseLimit.ConnsOutbound = logScale(2 * maxconns)
defaultLimits.SystemBaseLimit.Conns = logScale(4 * maxconns)

defaultLimits.SystemBaseLimit.StreamsInbound = logScale(16 * maxconns)
defaultLimits.SystemBaseLimit.StreamsOutbound = logScale(64 * maxconns)
defaultLimits.SystemBaseLimit.Streams = logScale(64 * maxconns)
// We want the floor of minOutbound conns to be no less than what was set above.
if minOutbound := logScale(2 * maxconns); minOutbound > defaultLimits.SystemBaseLimit.ConnsOutbound {
defaultLimits.SystemBaseLimit.ConnsOutbound = minOutbound
}

if 2*maxconns > defaultLimits.SystemBaseLimit.FD {
defaultLimits.SystemBaseLimit.FD = logScale(2 * maxconns)
}

defaultLimits.SystemBaseLimit.StreamsInbound = logScale(16 * maxconns)
defaultLimits.SystemBaseLimit.StreamsOutbound = logScale(64 * maxconns)
defaultLimits.SystemBaseLimit.Streams = logScale(64 * maxconns)

defaultLimits.ServiceBaseLimit.StreamsInbound = logScale(8 * maxconns)
defaultLimits.ServiceBaseLimit.StreamsOutbound = logScale(32 * maxconns)
defaultLimits.ServiceBaseLimit.Streams = logScale(32 * maxconns)
Expand All @@ -61,6 +72,8 @@ func adjustedDefaultLimits(cfg config.SwarmConfig) rcmgr.DefaultLimitConfig {
}
}

defaultLimits.SystemBaseLimit.Conns = defaultLimits.SystemBaseLimit.ConnsOutbound + defaultLimits.SystemBaseLimit.ConnsInbound

return defaultLimits
}

Expand Down

0 comments on commit a52d37d

Please sign in to comment.