Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: RM: Improve init RM message and fix final memory value. #9470

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/node/libp2p/rcmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func ResourceManager(cfg config.SwarmConfig) interface{} {
lrm.start(helpers.LifecycleCtx(mctx, lc))
manager = lrm
} else {
log.Debug("libp2p resource manager is disabled")
fmt.Println("go-libp2p resource manager protection disabled")
manager = network.NullResourceManager
}

Expand Down
17 changes: 15 additions & 2 deletions core/node/libp2p/rcmgr_defaults.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package libp2p

import (
"fmt"

"github.com/dustin/go-humanize"
"github.com/libp2p/go-libp2p"
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
Expand Down Expand Up @@ -54,6 +56,17 @@ func createDefaultLimitConfig(cfg config.SwarmConfig) (rcmgr.LimitConfig, error)

numFD := cfg.ResourceMgr.MaxFileDescriptors.WithDefault(int64(fd.GetNumFDs()) / 2)

// We want to see this message on startup, that's why we are using fmt instead of log.
fmt.Printf(`
Computing default go-libp2p Resource Manager limits based on:
- 'Swarm.ResourceMgr.MaxMemory': %q
- 'Swarm.ResourceMgr.MaxFileDescriptors': %d

Applying any user-supplied overrides on top.
Run 'ipfs swarm limit all' to see the resulting limits.

`, maxMemoryString, numFD)

scalingLimitConfig := rcmgr.ScalingLimitConfig{
SystemBaseLimit: rcmgr.BaseLimit{
Memory: int64(maxMemory),
Expand All @@ -74,8 +87,8 @@ func createDefaultLimitConfig(cfg config.SwarmConfig) (rcmgr.LimitConfig, error)
// Most limits don't see an increase because they're already infinite/bigEnough or at their max value.
// The values that should scale based on the amount of memory allocated to libp2p need to increase accordingly.
SystemLimitIncrease: rcmgr.BaseLimitIncrease{
Memory: rcmgr.DefaultLimits.SystemLimitIncrease.Memory,
FDFraction: rcmgr.DefaultLimits.SystemLimitIncrease.FDFraction,
Memory: 0,
FDFraction: 0,
Jorropo marked this conversation as resolved.
Show resolved Hide resolved

Conns: 0,
ConnsInbound: rcmgr.DefaultLimits.SystemLimitIncrease.ConnsInbound,
Expand Down
14 changes: 13 additions & 1 deletion test/sharness/t0060-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ test_expect_success "cleanup repo" '
'

test_init_ipfs
test_expect_success "set Resource Manager variables showed at startup" '
ipfs config --json Swarm.ResourceMgr.MaxFileDescriptors 1024 &&
ipfs config Swarm.ResourceMgr.MaxMemory 4GB
'
test_launch_ipfs_daemon

# this errors if we didn't --init $IPFS_PATH correctly
Expand Down Expand Up @@ -73,9 +77,17 @@ test_expect_success "ipfs gateway works with the correct allowed origin port" '
'

test_expect_success "ipfs daemon output looks good" '
STARTFILE="ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme" &&
STARTFILE="ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme"
ajnavarro marked this conversation as resolved.
Show resolved Hide resolved
echo "Initializing daemon..." >expected_daemon &&
ipfs version --all >> expected_daemon &&
echo "" >>expected_daemon &&
echo "Computing default go-libp2p Resource Manager limits based on:" >>expected_daemon &&
echo " - '"'"'Swarm.ResourceMgr.MaxMemory'"'"': \"4GB\"" >>expected_daemon &&
echo " - '"'"'Swarm.ResourceMgr.MaxFileDescriptors'"'"': 1024" >>expected_daemon &&
echo "" >>expected_daemon &&
echo "Applying any user-supplied overrides on top." >>expected_daemon &&
echo "Run '"'"'ipfs swarm limit all'"'"' to see the resulting limits." >>expected_daemon &&
echo "" >>expected_daemon &&
sed "s/^/Swarm listening on /" listen_addrs >>expected_daemon &&
sed "s/^/Swarm announcing /" local_addrs >>expected_daemon &&
echo "API server listening on '$API_MADDR'" >>expected_daemon &&
Expand Down