-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b5bfeb
commit 543f833
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// https://github.com/libp2p/go-libp2p/tree/master/p2p/host/resource-manager | ||
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) { | ||
// Start with the default scaling limits. | ||
scalingLimits := rcmgr.DefaultLimits | ||
|
||
// Add limits around included libp2p protocols | ||
libp2p.SetDefaultServiceLimits(&scalingLimits) | ||
|
||
// Turn the scaling limits into a concrete set of limits using `.AutoScale`. This | ||
// scales the limits proportional to your system memory. | ||
scaledDefaultLimits := scalingLimits.AutoScale() | ||
|
||
// Tweak certain settings | ||
cfg := rcmgr.PartialLimitConfig{ | ||
System: rcmgr.ResourceLimits{ | ||
ConnsOutbound: rcmgr.Unlimited, | ||
Conns: rcmgr.Unlimited, | ||
ConnsInbound: rcmgr.Unlimited, | ||
}, | ||
} | ||
|
||
// Create our limits by using our cfg and replacing the default values with values from `scaledDefaultLimits` | ||
limits := cfg.Build(scaledDefaultLimits) | ||
|
||
// The resource manager expects a limiter, se we create one from our limits. | ||
limiter := rcmgr.NewFixedLimiter(limits) | ||
|
||
// Initialize the resource manager | ||
rm, err := rcmgr.NewResourceManager(limiter) | ||
|
||
return rm, err | ||
} |