@cryptotaxi247 / kubo / commits / 377d4e993

Remove limitation by HighWater param.

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>

Antonio Navarro Perez committed Nov 15, 2022 at 17:22 UTC 377d4e9938eddb7c589e53c26d36b181e035cc08
3 files changed +16 -15
core/node/groups.go
+1 -1
@@ -147,7 +147,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
147 BaseLibP2P,
148
149 // Services (resource management)
150 - fx.Provide(libp2p.ResourceManager(cfg.Swarm, cfg.Experimental.AcceleratedDHTClient)),
150 + fx.Provide(libp2p.ResourceManager(cfg.Swarm)),
151 fx.Provide(libp2p.AddrFilters(cfg.Swarm.AddrFilters)),
152 fx.Provide(libp2p.AddrsFactory(cfg.Addresses.Announce, cfg.Addresses.AppendAnnounce, cfg.Addresses.NoAnnounce)),
153 fx.Provide(libp2p.SmuxTransport(cfg.Swarm.Transports)),
core/node/libp2p/rcmgr.go
+3 -3
@@ -29,7 +29,7 @@ const NetLimitTraceFilename = "rcmgr.json.gz"
29
30 var ErrNoResourceMgr = fmt.Errorf("missing ResourceMgr: make sure the daemon is running with Swarm.ResourceMgr.Enabled")
31
32 -func ResourceManager(cfg config.SwarmConfig, acceleratedDHT bool) interface{} {
32 +func ResourceManager(cfg config.SwarmConfig) interface{} {
33 return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, repo repo.Repo) (network.ResourceManager, Libp2pOpts, error) {
34 var manager network.ResourceManager
35 var opts Libp2pOpts
@@ -52,7 +52,7 @@ func ResourceManager(cfg config.SwarmConfig, acceleratedDHT bool) interface{} {
52 return nil, opts, fmt.Errorf("opening IPFS_PATH: %w", err)
53 }
54
55 - limits, err := createDefaultLimitConfig(cfg, acceleratedDHT)
55 + limits, err := createDefaultLimitConfig(cfg)
56 if err != nil {
57 return nil, opts, err
58 }
@@ -513,7 +513,7 @@ func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (r
513 return result, fmt.Errorf("reading config to reset limit: %w", err)
514 }
515
516 - defaults, err := createDefaultLimitConfig(cfg.Swarm, cfg.Experimental.AcceleratedDHTClient)
516 + defaults, err := createDefaultLimitConfig(cfg.Swarm)
517 if err != nil {
518 return result, fmt.Errorf("creating default limit config: %w", err)
519 }
core/node/libp2p/rcmgr_defaults.go
+12 -11
@@ -57,9 +57,6 @@ var noLimitIncrease = rcmgr.BaseLimitIncrease{
57 // - cfg.ResourceMgr.MaxFileDescriptors: This is the maximum number of file descriptors to allow libp2p to use.
58 // libp2p's resource manager will prevent additional file descriptor consumption while this limit is hit.
59 // If this value isn't specified, the maximum between 1/2 of system FD limit and 4096 is used.
60 -// - Swarm.ConnMgr.HighWater: If a connection manager is specified, libp2p's resource manager
61 -// will allow 2x more connections than the HighWater mark
62 -// so the connection manager has "space and time" to close "least useful" connections.
60 //
61 // With these inputs defined, limits are created at the system, transient, and peer scopes.
62 // Other scopes are ignored (by being set to infinity).
@@ -89,7 +86,18 @@ var noLimitIncrease = rcmgr.BaseLimitIncrease{
86 // maxMemory, maxFD, or maxConns with Swarm.HighWater.ConnMgr.
87 // 3. Power user - They specify all the limits they want set via Swarm.ResourceMgr.Limits
88 // and we don't do any defaults/overrides. We pass that config blindly into libp2p resource manager.
92 -func createDefaultLimitConfig(cfg config.SwarmConfig, acceleratedDHT bool) (rcmgr.LimitConfig, error) {
89 +//
90 +// Note that within libp2p. Swarm.ConnMgr settings have no impact on libp2p's resource manager limits.
91 +// See https://github.com/libp2p/go-libp2p/blob/master/p2p/host/resource-manager/README.md#connmanager-vs-resource-manager
92 +// and https://github.com/libp2p/go-libp2p/issues/1640
93 +// We also don't layer on extra logic in this function because SystemBaseLimit.Conns is already "bigEnough".
94 +// There is headroom for the connection manager to apply any Swarm.ConnMgr.HighWater mark.
95 +// We're keeping things simple by avoiding any interaction between libp2p's resource manager and connection manager.
96 +// For example we don't set SystemBaseLimit.Conns to be related to Swarm.ConnMgr.HighWater.
97 +// SystemBaseLimit.Conns is "bigEnough" and won't won't limit total connections.
98 +// (We will limit SystemBaseLimit.ConnsInbound though.)
99 +// The Swarm.ConnMgr can manage connections based on Swarm.ConnMgr.HighWater.
100 +func createDefaultLimitConfig(cfg config.SwarmConfig) (rcmgr.LimitConfig, error) {
101 maxMemoryDefaultString := humanize.Bytes(uint64(memory.TotalMemory()) / 8)
102 maxMemoryString := cfg.ResourceMgr.MaxMemory.WithDefault(maxMemoryDefaultString)
103 maxMemory, err := humanize.ParseBytes(maxMemoryString)
@@ -217,12 +225,5 @@ func createDefaultLimitConfig(cfg config.SwarmConfig, acceleratedDHT bool) (rcmg
225
226 defaultLimitConfig := scalingLimitConfig.Scale(int64(maxMemory), int(numFD))
227
220 - // If a high water mark is set (ignore when using accelerated DHT):
221 - if cfg.ConnMgr.Type == "basic" && !acceleratedDHT {
222 - // set the connection limit higher than high water mark so that the ConnMgr has "space and time" to close "least useful" connections.
223 - defaultLimitConfig.System.Conns = 2 * cfg.ConnMgr.HighWater
224 - log.Info("adjusted default resource manager System.Conns limits to match ConnMgr.HighWater value of %s", cfg.ConnMgr.HighWater)
225 - }
226 -
228 return defaultLimitConfig, nil
229 }