@cryptotaxi247 / kubo / commits / 62a9829ca

Reintroduce connmgr hi watermark logic

Marco Munizaga committed Jul 6, 2022 at 10:36 UTC 62a9829cafceb5b22943d9bf94ff8b860062306b
2 files changed +50 -54
core/node/libp2p/rcmgr.go
+1 -3
@@ -55,9 +55,7 @@ func ResourceManager(cfg config.SwarmConfig) interface{} {
55 return nil, opts, fmt.Errorf("opening IPFS_PATH: %w", err)
56 }
57
58 - limitCfg := adjustedDefaultLimits(cfg)
59 - libp2p.SetDefaultServiceLimits(limitCfg)
60 - limits := limitCfg.AutoScale()
58 + limits := adjustedDefaultLimits(cfg)
59
60 if cfg.ResourceMgr.Limits != nil {
61 l := *cfg.ResourceMgr.Limits
core/node/libp2p/rcmgr_defaults.go
+49 -51
@@ -18,64 +18,62 @@ import (
18
19 // adjustedDefaultLimits allows for tweaking defaults based on external factors,
20 // such as values in Swarm.ConnMgr.HiWater config.
21 -func adjustedDefaultLimits(cfg config.SwarmConfig) *rcmgr.ScalingLimitConfig {
21 +func adjustedDefaultLimits(cfg config.SwarmConfig) rcmgr.LimitConfig {
22 // Run checks to avoid introducing regressions
23 if os.Getenv("IPFS_CHECK_RCMGR_DEFAULTS") != "" {
24 // FIXME: Broken. Being tracked in https://github.com/ipfs/go-ipfs/issues/8949.
25 checkImplicitDefaults()
26 }
27 - return &rcmgr.DefaultLimits
27 + defaultLimits := rcmgr.DefaultLimits
28 + libp2p.SetDefaultServiceLimits(&defaultLimits)
29 +
30 + // Adjust limits
31 + // (based on https://github.com/filecoin-project/lotus/pull/8318/files)
32 + // - if Swarm.ConnMgr.HighWater is too high, adjust Conn/FD/Stream limits
33 +
34 + // Outbound conns and FDs are set very high to allow for the accelerated DHT client to (re)load its routing table.
35 + // Currently it doesn't gracefully handle RM throttling--once it does we can lower these.
36 + // High outbound conn limits are considered less of a DoS risk than high inbound conn limits.
37 + // Also note that, due to the behavior of the accelerated DHT client, we don't need many streams, just conns.
38 + if minOutbound := 65536; defaultLimits.SystemBaseLimit.ConnsOutbound < minOutbound {
39 + defaultLimits.SystemBaseLimit.ConnsOutbound = minOutbound
40 + }
41 + if minFD := 4096; defaultLimits.SystemBaseLimit.FD < minFD {
42 + defaultLimits.SystemBaseLimit.FD = minFD
43 + }
44 + defaultLimitConfig := defaultLimits.AutoScale()
45
29 - // // Adjust limits
30 - // // (based on https://github.com/filecoin-project/lotus/pull/8318/files)
31 - // // - give it more memory, up to 4G, min of 1G
32 - // // - if Swarm.ConnMgr.HighWater is too high, adjust Conn/FD/Stream limits
33 - // defaultLimits := rcmgr.DefaultLimits.WithSystemMemory(.125, 1<<30, 4<<30)
34 - //
35 - // // Outbound conns and FDs are set very high to allow for the accelerated DHT client to (re)load its routing table.
36 - // // Currently it doesn't gracefully handle RM throttling--once it does we can lower these.
37 - // // High outbound conn limits are considered less of a DoS risk than high inbound conn limits.
38 - // // Also note that, due to the behavior of the accelerated DHT client, we don't need many streams, just conns.
39 - // if minOutbound := 65536; defaultLimits.SystemBaseLimit.ConnsOutbound < minOutbound {
40 - // defaultLimits.SystemBaseLimit.ConnsOutbound = minOutbound
41 - // }
42 - // if minFD := 4096; defaultLimits.SystemBaseLimit.FD < minFD {
43 - // defaultLimits.SystemBaseLimit.FD = minFD
44 - // }
45 - //
46 // Do we need to adjust due to Swarm.ConnMgr.HighWater?
47 - // if cfg.ConnMgr.Type == "basic" {
48 - // maxconns := cfg.ConnMgr.HighWater
49 - // if 2*maxconns > defaultLimits.SystemBaseLimit.ConnsInbound {
50 - // // Conns should be at least 2x larger than the high water to allow for two conns per peer (TCP+QUIC).
51 - // defaultLimits.SystemBaseLimit.ConnsInbound = logScale(2 * maxconns)
52 - //
53 - // // We want the floor of minOutbound conns to be no less than what was set above.
54 - // if minOutbound := logScale(2 * maxconns); minOutbound > defaultLimits.SystemBaseLimit.ConnsOutbound {
55 - // defaultLimits.SystemBaseLimit.ConnsOutbound = minOutbound
56 - // }
57 - //
58 - // if 2*maxconns > defaultLimits.SystemBaseLimit.FD {
59 - // defaultLimits.SystemBaseLimit.FD = logScale(2 * maxconns)
60 - // }
61 - //
62 - // defaultLimits.SystemBaseLimit.StreamsInbound = logScale(16 * maxconns)
63 - // defaultLimits.SystemBaseLimit.StreamsOutbound = logScale(64 * maxconns)
64 - // defaultLimits.SystemBaseLimit.Streams = logScale(64 * maxconns)
65 - //
66 - // defaultLimits.ServiceBaseLimit.StreamsInbound = logScale(8 * maxconns)
67 - // defaultLimits.ServiceBaseLimit.StreamsOutbound = logScale(32 * maxconns)
68 - // defaultLimits.ServiceBaseLimit.Streams = logScale(32 * maxconns)
69 - //
70 - // defaultLimits.ProtocolBaseLimit.StreamsInbound = logScale(8 * maxconns)
71 - // defaultLimits.ProtocolBaseLimit.StreamsOutbound = logScale(32 * maxconns)
72 - // defaultLimits.ProtocolBaseLimit.Streams = logScale(32 * maxconns)
73 - // }
74 - // }
75 - //
76 - // defaultLimits.SystemBaseLimit.Conns = defaultLimits.SystemBaseLimit.ConnsOutbound + defaultLimits.SystemBaseLimit.ConnsInbound
77 - //
78 - // return defaultLimits
47 + if cfg.ConnMgr.Type == "basic" {
48 + maxconns := cfg.ConnMgr.HighWater
49 + if 2*maxconns > defaultLimitConfig.System.ConnsInbound {
50 + // adjust conns to 2x to allow for two conns per peer (TCP+QUIC)
51 + defaultLimitConfig.System.ConnsInbound = logScale(2 * maxconns)
52 + defaultLimitConfig.System.ConnsOutbound = logScale(2 * maxconns)
53 + defaultLimitConfig.System.Conns = logScale(4 * maxconns)
54 +
55 + defaultLimitConfig.System.StreamsInbound = logScale(16 * maxconns)
56 + defaultLimitConfig.System.StreamsOutbound = logScale(64 * maxconns)
57 + defaultLimitConfig.System.Streams = logScale(64 * maxconns)
58 +
59 + if 2*maxconns > defaultLimitConfig.System.FD {
60 + defaultLimitConfig.System.FD = logScale(2 * maxconns)
61 + }
62 +
63 + defaultLimitConfig.ServiceDefault.StreamsInbound = logScale(8 * maxconns)
64 + defaultLimitConfig.ServiceDefault.StreamsOutbound = logScale(32 * maxconns)
65 + defaultLimitConfig.ServiceDefault.Streams = logScale(32 * maxconns)
66 +
67 + defaultLimitConfig.ProtocolDefault.StreamsInbound = logScale(8 * maxconns)
68 + defaultLimitConfig.ProtocolDefault.StreamsOutbound = logScale(32 * maxconns)
69 + defaultLimitConfig.ProtocolDefault.Streams = logScale(32 * maxconns)
70 +
71 + log.Info("adjusted default resource manager limits")
72 + }
73 +
74 + }
75 +
76 + return defaultLimitConfig
77 }
78
79 func logScale(val int) int {