Skip to content

Commit

Permalink
Remove limitation by HighWater param.
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
  • Loading branch information
ajnavarro committed Nov 15, 2022
1 parent 96724a1 commit 14fbf0b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
6 changes: 3 additions & 3 deletions core/node/libp2p/rcmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down
23 changes: 12 additions & 11 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,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)
Expand Down Expand Up @@ -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
}

0 comments on commit 14fbf0b

Please sign in to comment.