diff --git a/core/node/libp2p/rcmgr_defaults.go b/core/node/libp2p/rcmgr_defaults.go index 3ff8b55dd26..f05e1f4f3c2 100644 --- a/core/node/libp2p/rcmgr_defaults.go +++ b/core/node/libp2p/rcmgr_defaults.go @@ -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). @@ -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) @@ -132,9 +140,31 @@ 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{ + Memory: rcmgr.DefaultLimits.TransientBaseLimit.Memory, + FD: rcmgr.DefaultLimits.TransientBaseLimit.FD, + + Conns: bigEnough, + ConnsInbound: rcmgr.DefaultLimits.TransientBaseLimit.ConnsInbound, + ConnsOutbound: bigEnough, + + Streams: bigEnough, + StreamsInbound: rcmgr.DefaultLimits.TransientBaseLimit.StreamsInbound, + StreamsOutbound: bigEnough, + }, + + 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. @@ -197,12 +227,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 }