From 14fbf0b3bf2cf6ca672f71355d26e1381502ea32 Mon Sep 17 00:00:00 2001 From: Antonio Navarro Perez Date: Tue, 15 Nov 2022 17:22:41 +0100 Subject: [PATCH] Remove limitation by HighWater param. Signed-off-by: Antonio Navarro Perez --- core/node/groups.go | 2 +- core/node/libp2p/rcmgr.go | 6 +++--- core/node/libp2p/rcmgr_defaults.go | 23 ++++++++++++----------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/core/node/groups.go b/core/node/groups.go index 6a821becab2..fca984650d9 100644 --- a/core/node/groups.go +++ b/core/node/groups.go @@ -147,7 +147,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option { BaseLibP2P, // Services (resource management) - fx.Provide(libp2p.ResourceManager(cfg.Swarm, cfg.Experimental.AcceleratedDHTClient)), + fx.Provide(libp2p.ResourceManager(cfg.Swarm)), fx.Provide(libp2p.AddrFilters(cfg.Swarm.AddrFilters)), fx.Provide(libp2p.AddrsFactory(cfg.Addresses.Announce, cfg.Addresses.AppendAnnounce, cfg.Addresses.NoAnnounce)), fx.Provide(libp2p.SmuxTransport(cfg.Swarm.Transports)), diff --git a/core/node/libp2p/rcmgr.go b/core/node/libp2p/rcmgr.go index 0de4fbe6408..49c9d382399 100644 --- a/core/node/libp2p/rcmgr.go +++ b/core/node/libp2p/rcmgr.go @@ -29,7 +29,7 @@ const NetLimitTraceFilename = "rcmgr.json.gz" var ErrNoResourceMgr = fmt.Errorf("missing ResourceMgr: make sure the daemon is running with Swarm.ResourceMgr.Enabled") -func ResourceManager(cfg config.SwarmConfig, acceleratedDHT bool) interface{} { +func ResourceManager(cfg config.SwarmConfig) interface{} { return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, repo repo.Repo) (network.ResourceManager, Libp2pOpts, error) { var manager network.ResourceManager var opts Libp2pOpts @@ -52,7 +52,7 @@ func ResourceManager(cfg config.SwarmConfig, acceleratedDHT bool) interface{} { return nil, opts, fmt.Errorf("opening IPFS_PATH: %w", err) } - limits, err := createDefaultLimitConfig(cfg, acceleratedDHT) + limits, err := createDefaultLimitConfig(cfg) if err != nil { return nil, opts, err } @@ -513,7 +513,7 @@ func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (r return result, fmt.Errorf("reading config to reset limit: %w", err) } - defaults, err := createDefaultLimitConfig(cfg.Swarm, cfg.Experimental.AcceleratedDHTClient) + defaults, err := createDefaultLimitConfig(cfg.Swarm) if err != nil { return result, fmt.Errorf("creating default limit config: %w", err) } diff --git a/core/node/libp2p/rcmgr_defaults.go b/core/node/libp2p/rcmgr_defaults.go index 2c1f3d93a8c..84eedf7ed50 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,7 +86,18 @@ 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. -func createDefaultLimitConfig(cfg config.SwarmConfig, acceleratedDHT bool) (rcmgr.LimitConfig, error) { +// +// 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) maxMemory, err := humanize.ParseBytes(maxMemoryString) @@ -217,12 +225,5 @@ func createDefaultLimitConfig(cfg config.SwarmConfig, acceleratedDHT bool) (rcmg defaultLimitConfig := scalingLimitConfig.Scale(int64(maxMemory), int(numFD)) - // If a high water mark is set (ignore when using accelerated DHT): - if cfg.ConnMgr.Type == "basic" && !acceleratedDHT { - // 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 }