Merge branch 'master' into 9171-add-retries-to-mpool-push-message
This commit is contained in:
+17
-58
@@ -108,33 +108,14 @@ func (a *NetAPI) NetLimit(ctx context.Context, scope string) (result api.NetLimi
|
||||
}
|
||||
|
||||
limit := limiter.Limit()
|
||||
switch l := limit.(type) {
|
||||
case *rcmgr.StaticLimit:
|
||||
result.Memory = l.Memory
|
||||
result.Streams = l.BaseLimit.Streams
|
||||
result.StreamsInbound = l.BaseLimit.StreamsInbound
|
||||
result.StreamsOutbound = l.BaseLimit.StreamsOutbound
|
||||
result.Conns = l.BaseLimit.Conns
|
||||
result.ConnsInbound = l.BaseLimit.ConnsInbound
|
||||
result.ConnsOutbound = l.BaseLimit.ConnsOutbound
|
||||
result.FD = l.BaseLimit.FD
|
||||
|
||||
case *rcmgr.DynamicLimit:
|
||||
result.Dynamic = true
|
||||
result.MemoryFraction = l.MemoryLimit.MemoryFraction
|
||||
result.MinMemory = l.MemoryLimit.MinMemory
|
||||
result.MaxMemory = l.MemoryLimit.MaxMemory
|
||||
result.Streams = l.BaseLimit.Streams
|
||||
result.StreamsInbound = l.BaseLimit.StreamsInbound
|
||||
result.StreamsOutbound = l.BaseLimit.StreamsOutbound
|
||||
result.Conns = l.BaseLimit.Conns
|
||||
result.ConnsInbound = l.BaseLimit.ConnsInbound
|
||||
result.ConnsOutbound = l.BaseLimit.ConnsOutbound
|
||||
result.FD = l.BaseLimit.FD
|
||||
|
||||
default:
|
||||
return xerrors.Errorf("unknown limit type %T", limit)
|
||||
}
|
||||
result.Memory = limit.GetMemoryLimit()
|
||||
result.Streams = limit.GetStreamTotalLimit()
|
||||
result.StreamsInbound = limit.GetStreamLimit(network.DirInbound)
|
||||
result.StreamsOutbound = limit.GetStreamLimit(network.DirOutbound)
|
||||
result.Conns = limit.GetConnTotalLimit()
|
||||
result.ConnsInbound = limit.GetConnLimit(network.DirInbound)
|
||||
result.ConnsOutbound = limit.GetConnLimit(network.DirOutbound)
|
||||
result.FD = limit.GetFDLimit()
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -189,37 +170,15 @@ func (a *NetAPI) NetSetLimit(ctx context.Context, scope string, limit api.NetLim
|
||||
return xerrors.Errorf("resource scope doesn't implement ResourceScopeLimiter interface")
|
||||
}
|
||||
|
||||
var newLimit rcmgr.Limit
|
||||
if limit.Dynamic {
|
||||
newLimit = &rcmgr.DynamicLimit{
|
||||
MemoryLimit: rcmgr.MemoryLimit{
|
||||
MemoryFraction: limit.MemoryFraction,
|
||||
MinMemory: limit.MinMemory,
|
||||
MaxMemory: limit.MaxMemory,
|
||||
},
|
||||
BaseLimit: rcmgr.BaseLimit{
|
||||
Streams: limit.Streams,
|
||||
StreamsInbound: limit.StreamsInbound,
|
||||
StreamsOutbound: limit.StreamsOutbound,
|
||||
Conns: limit.Conns,
|
||||
ConnsInbound: limit.ConnsInbound,
|
||||
ConnsOutbound: limit.ConnsOutbound,
|
||||
FD: limit.FD,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
newLimit = &rcmgr.StaticLimit{
|
||||
Memory: limit.Memory,
|
||||
BaseLimit: rcmgr.BaseLimit{
|
||||
Streams: limit.Streams,
|
||||
StreamsInbound: limit.StreamsInbound,
|
||||
StreamsOutbound: limit.StreamsOutbound,
|
||||
Conns: limit.Conns,
|
||||
ConnsInbound: limit.ConnsInbound,
|
||||
ConnsOutbound: limit.ConnsOutbound,
|
||||
FD: limit.FD,
|
||||
},
|
||||
}
|
||||
newLimit := &rcmgr.BaseLimit{
|
||||
Memory: limit.Memory,
|
||||
Streams: limit.Streams,
|
||||
StreamsInbound: limit.StreamsInbound,
|
||||
StreamsOutbound: limit.StreamsOutbound,
|
||||
Conns: limit.Conns,
|
||||
ConnsInbound: limit.ConnsInbound,
|
||||
ConnsOutbound: limit.ConnsOutbound,
|
||||
FD: limit.FD,
|
||||
}
|
||||
|
||||
limiter.SetLimit(newLimit)
|
||||
|
||||
+48
-24
@@ -14,7 +14,10 @@ import (
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/libp2p/go-libp2p-core/protocol"
|
||||
rcmgr "github.com/libp2p/go-libp2p-resource-manager"
|
||||
"github.com/libp2p/go-libp2p-resource-manager/obs"
|
||||
rcmgrObs "github.com/libp2p/go-libp2p-resource-manager/obs"
|
||||
"go.opencensus.io/stats"
|
||||
"go.opencensus.io/stats/view"
|
||||
"go.opencensus.io/tag"
|
||||
"go.uber.org/fx"
|
||||
|
||||
@@ -36,38 +39,52 @@ func ResourceManager(connMgrHi uint) func(lc fx.Lifecycle, repo repo.LockedRepo)
|
||||
// enable debug logs for rcmgr
|
||||
logging.SetLogLevel("rcmgr", "debug")
|
||||
|
||||
// Adjust default limits
|
||||
// Adjust default defaultLimits
|
||||
// - give it more memory, up to 4G, min of 1G
|
||||
// - if maxconns are too high, adjust Conn/FD/Stream limits
|
||||
defaultLimits := rcmgr.DefaultLimits.WithSystemMemory(.125, 1<<30, 4<<30)
|
||||
// - if maxconns are too high, adjust Conn/FD/Stream defaultLimits
|
||||
defaultLimits := rcmgr.DefaultLimits
|
||||
|
||||
// TODO: also set appropriate default limits for lotus protocols
|
||||
libp2p.SetDefaultServiceLimits(&defaultLimits)
|
||||
|
||||
// Minimum 1GB of memory
|
||||
defaultLimits.SystemBaseLimit.Memory = 1 << 30
|
||||
// For every extra 1GB of memory we have available, increase our limit by 1GiB
|
||||
defaultLimits.SystemLimitIncrease.Memory = 1 << 30
|
||||
defaultLimitConfig := defaultLimits.AutoScale()
|
||||
if defaultLimitConfig.System.Memory > 4<<30 {
|
||||
// Cap our memory limit
|
||||
defaultLimitConfig.System.Memory = 4 << 30
|
||||
}
|
||||
|
||||
maxconns := int(connMgrHi)
|
||||
if 2*maxconns > defaultLimits.SystemBaseLimit.ConnsInbound {
|
||||
if 2*maxconns > defaultLimitConfig.System.ConnsInbound {
|
||||
// adjust conns to 2x to allow for two conns per peer (TCP+QUIC)
|
||||
defaultLimits.SystemBaseLimit.ConnsInbound = logScale(2 * maxconns)
|
||||
defaultLimits.SystemBaseLimit.ConnsOutbound = logScale(2 * maxconns)
|
||||
defaultLimits.SystemBaseLimit.Conns = logScale(4 * maxconns)
|
||||
defaultLimitConfig.System.ConnsInbound = logScale(2 * maxconns)
|
||||
defaultLimitConfig.System.ConnsOutbound = logScale(2 * maxconns)
|
||||
defaultLimitConfig.System.Conns = logScale(4 * maxconns)
|
||||
|
||||
defaultLimits.SystemBaseLimit.StreamsInbound = logScale(16 * maxconns)
|
||||
defaultLimits.SystemBaseLimit.StreamsOutbound = logScale(64 * maxconns)
|
||||
defaultLimits.SystemBaseLimit.Streams = logScale(64 * maxconns)
|
||||
defaultLimitConfig.System.StreamsInbound = logScale(16 * maxconns)
|
||||
defaultLimitConfig.System.StreamsOutbound = logScale(64 * maxconns)
|
||||
defaultLimitConfig.System.Streams = logScale(64 * maxconns)
|
||||
|
||||
if 2*maxconns > defaultLimits.SystemBaseLimit.FD {
|
||||
defaultLimits.SystemBaseLimit.FD = logScale(2 * maxconns)
|
||||
if 2*maxconns > defaultLimitConfig.System.FD {
|
||||
defaultLimitConfig.System.FD = logScale(2 * maxconns)
|
||||
}
|
||||
|
||||
defaultLimits.ServiceBaseLimit.StreamsInbound = logScale(8 * maxconns)
|
||||
defaultLimits.ServiceBaseLimit.StreamsOutbound = logScale(32 * maxconns)
|
||||
defaultLimits.ServiceBaseLimit.Streams = logScale(32 * maxconns)
|
||||
defaultLimitConfig.ServiceDefault.StreamsInbound = logScale(8 * maxconns)
|
||||
defaultLimitConfig.ServiceDefault.StreamsOutbound = logScale(32 * maxconns)
|
||||
defaultLimitConfig.ServiceDefault.Streams = logScale(32 * maxconns)
|
||||
|
||||
defaultLimits.ProtocolBaseLimit.StreamsInbound = logScale(8 * maxconns)
|
||||
defaultLimits.ProtocolBaseLimit.StreamsOutbound = logScale(32 * maxconns)
|
||||
defaultLimits.ProtocolBaseLimit.Streams = logScale(32 * maxconns)
|
||||
defaultLimitConfig.ProtocolDefault.StreamsInbound = logScale(8 * maxconns)
|
||||
defaultLimitConfig.ProtocolDefault.StreamsOutbound = logScale(32 * maxconns)
|
||||
defaultLimitConfig.ProtocolDefault.Streams = logScale(32 * maxconns)
|
||||
|
||||
log.Info("adjusted default resource manager limits")
|
||||
}
|
||||
|
||||
// initialize
|
||||
var limiter *rcmgr.BasicLimiter
|
||||
var limiter rcmgr.Limiter
|
||||
var opts []rcmgr.Option
|
||||
|
||||
repoPath := repo.Path()
|
||||
@@ -78,22 +95,29 @@ func ResourceManager(connMgrHi uint) func(lc fx.Lifecycle, repo repo.LockedRepo)
|
||||
switch {
|
||||
case err == nil:
|
||||
defer limitsIn.Close() //nolint:errcheck
|
||||
limiter, err = rcmgr.NewLimiterFromJSON(limitsIn, defaultLimits)
|
||||
limiter, err = rcmgr.NewLimiterFromJSON(limitsIn, defaultLimitConfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing limit file: %w", err)
|
||||
}
|
||||
|
||||
case errors.Is(err, os.ErrNotExist):
|
||||
limiter = rcmgr.NewStaticLimiter(defaultLimits)
|
||||
limiter = rcmgr.NewFixedLimiter(defaultLimitConfig)
|
||||
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: also set appropriate default limits for lotus protocols
|
||||
libp2p.SetDefaultServiceLimits(limiter)
|
||||
str, err := rcmgrObs.NewStatsTraceReporter()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating resource manager stats reporter: %w", err)
|
||||
}
|
||||
err = view.Register(obs.DefaultViews...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error registering rcmgr metrics: %w", err)
|
||||
}
|
||||
|
||||
opts = append(opts, rcmgr.WithMetrics(rcmgrMetrics{}))
|
||||
// Metrics
|
||||
opts = append(opts, rcmgr.WithMetrics(rcmgrMetrics{}), rcmgr.WithTraceReporter(str))
|
||||
|
||||
if os.Getenv("LOTUS_DEBUG_RCMGR") != "" {
|
||||
debugPath := filepath.Join(repoPath, "debug")
|
||||
|
||||
Reference in New Issue
Block a user