Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Stop RM errors when using acceleratedDHT #9407

Merged
merged 4 commits into from
Nov 15, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions core/node/libp2p/rcmgr_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ var noLimitIncrease = rcmgr.BaseLimitIncrease{
// - cfg.ResourceMgr.MaxFileDescriptors: This is the maximum number of file descriptors to allow libp2p to use.
// libp2p's resource manager will prevent additional file descriptor consumption while this limit is hit.
// If this value isn't specified, the maximum between 1/2 of system FD limit and 4096 is used.
// - Swarm.ConnMgr.HighWater: If a connection manager is specified, libp2p's resource manager
// will allow 2x more connections than the HighWater mark
// so the connection manager has "space and time" to close "least useful" connections.
//
// With these inputs defined, limits are created at the system, transient, and peer scopes.
// Other scopes are ignored (by being set to infinity).
Expand Down Expand Up @@ -89,6 +86,17 @@ var noLimitIncrease = rcmgr.BaseLimitIncrease{
// maxMemory, maxFD, or maxConns with Swarm.HighWater.ConnMgr.
// 3. Power user - They specify all the limits they want set via Swarm.ResourceMgr.Limits
// and we don't do any defaults/overrides. We pass that config blindly into libp2p resource manager.
//
// Note that within libp2p. Swarm.ConnMgr settings have no impact on libp2p's resource manager limits.
// See https://github.com/libp2p/go-libp2p/blob/master/p2p/host/resource-manager/README.md#connmanager-vs-resource-manager
// and https://github.com/libp2p/go-libp2p/issues/1640
// We also don't layer on extra logic in this function because SystemBaseLimit.Conns is already "bigEnough".
// There is headroom for the connection manager to apply any Swarm.ConnMgr.HighWater mark.
// We're keeping things simple by avoiding any interaction between libp2p's resource manager and connection manager.
// For example we don't set SystemBaseLimit.Conns to be related to Swarm.ConnMgr.HighWater.
// SystemBaseLimit.Conns is "bigEnough" and won't won't limit total connections.
// (We will limit SystemBaseLimit.ConnsInbound though.)
// The Swarm.ConnMgr can manage connections based on Swarm.ConnMgr.HighWater.
func createDefaultLimitConfig(cfg config.SwarmConfig) (rcmgr.LimitConfig, error) {
maxMemoryDefaultString := humanize.Bytes(uint64(memory.TotalMemory()) / 8)
maxMemoryString := cfg.ResourceMgr.MaxMemory.WithDefault(maxMemoryDefaultString)
Expand Down Expand Up @@ -132,9 +140,29 @@ func createDefaultLimitConfig(cfg config.SwarmConfig) (rcmgr.LimitConfig, error)
StreamsOutbound: 0,
},

// Just go with what libp2p does
TransientBaseLimit: rcmgr.DefaultLimits.TransientBaseLimit,
TransientLimitIncrease: rcmgr.DefaultLimits.TransientLimitIncrease,
TransientBaseLimit: rcmgr.BaseLimit{
Streams: bigEnough,
StreamsInbound: rcmgr.DefaultLimits.TransientBaseLimit.StreamsInbound,
StreamsOutbound: bigEnough,
Conns: bigEnough,
ConnsInbound: rcmgr.DefaultLimits.TransientBaseLimit.ConnsInbound,
ConnsOutbound: bigEnough,
FD: rcmgr.DefaultLimits.TransientBaseLimit.FD,
Memory: rcmgr.DefaultLimits.TransientBaseLimit.Memory,
ajnavarro marked this conversation as resolved.
Show resolved Hide resolved
},

TransientLimitIncrease: rcmgr.BaseLimitIncrease{
Memory: rcmgr.DefaultLimits.TransientLimitIncrease.Memory,
FDFraction: rcmgr.DefaultLimits.TransientLimitIncrease.FDFraction,

Conns: 0,
ConnsInbound: rcmgr.DefaultLimits.TransientLimitIncrease.ConnsInbound,
ConnsOutbound: 0,

Streams: 0,
StreamsInbound: rcmgr.DefaultLimits.TransientLimitIncrease.StreamsInbound,
StreamsOutbound: 0,
},

// Lets get out of the way of the allow list functionality.
// If someone specified "Swarm.ResourceMgr.Allowlist" we should let it go through.
Expand Down Expand Up @@ -197,12 +225,5 @@ func createDefaultLimitConfig(cfg config.SwarmConfig) (rcmgr.LimitConfig, error)

defaultLimitConfig := scalingLimitConfig.Scale(int64(maxMemory), int(numFD))

// If a high water mark is set:
if cfg.ConnMgr.Type == "basic" {
// set the connection limit higher than high water mark so that the ConnMgr has "space and time" to close "least useful" connections.
defaultLimitConfig.System.Conns = 2 * cfg.ConnMgr.HighWater
log.Info("adjusted default resource manager System.Conns limits to match ConnMgr.HighWater value of %s", cfg.ConnMgr.HighWater)
}

return defaultLimitConfig, nil
}