Skip to content

Commit

Permalink
fix: add resource manager tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta committed Mar 3, 2023
1 parent 7b5bfeb commit 05fb386
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ type daemon struct {
}

func NewDaemon() *daemon {
rm, err := NewResourceManager()
if err != nil {
panic(err)
}

c, err := connmgr.NewConnManager(600, 900, connmgr.WithGracePeriod(time.Second*30))
if err != nil {
panic(err)
Expand All @@ -39,6 +44,7 @@ func NewDaemon() *daemon {
h, err := libp2p.New(
libp2p.ConnectionManager(c),
libp2p.ConnectionGater(&privateAddrFilterConnectionGater{}),
libp2p.ResourceManager(rm),
)
if err != nil {
panic(err)
Expand Down
31 changes: 31 additions & 0 deletions resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/network"
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
)

func NewResourceManager() (network.ResourceManager, error) {
// Copied from:
// https://github.com/libp2p/go-libp2p/blob/98837aad1591a9c5834fb6589318ee443cd12fe3/p2p/host/resource-manager/README.md

scalingLimits := rcmgr.DefaultLimits
libp2p.SetDefaultServiceLimits(&scalingLimits)

scaledDefaultLimits := scalingLimits.AutoScale()

cfg := rcmgr.PartialLimitConfig{
System: rcmgr.ResourceLimits{
ConnsOutbound: rcmgr.Unlimited,
Conns: rcmgr.Unlimited,
ConnsInbound: rcmgr.Unlimited,
},
}

limits := cfg.Build(scaledDefaultLimits)
limiter := rcmgr.NewFixedLimiter(limits)
rm, err := rcmgr.NewResourceManager(limiter)

return rm, err
}

0 comments on commit 05fb386

Please sign in to comment.