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(network): set connection limit for the resource manager #775

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 network/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (g *gossipService) onReceiveMessage(m *lp2pps.Message) {
return
}

g.logger.Debug("receiving new gossip message",
g.logger.Trace("receiving new gossip message",
"source", m.GetFrom(), "from", m.ReceivedFrom)
event := &GossipMessage{
Source: m.GetFrom(),
Expand Down
13 changes: 10 additions & 3 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,15 @@
return nil, LibP2PError{Err: err}
}

rmgr, err := lp2prcmgr.NewResourceManager(
lp2prcmgr.NewFixedLimiter(lp2prcmgr.DefaultLimits.AutoScale()),
maxconns := conf.MaxConns
changes := lp2prcmgr.PartialLimitConfig{}
changes.System.ConnsInbound = lp2prcmgr.LimitVal(2 * maxconns)
changes.System.ConnsOutbound = lp2prcmgr.LimitVal(2 * maxconns)
changes.System.Conns = lp2prcmgr.LimitVal(4 * maxconns)
limit := changes.Build(lp2prcmgr.DefaultLimits.AutoScale())

resMgr, err := lp2prcmgr.NewResourceManager(
lp2prcmgr.NewFixedLimiter(limit),
lp2prcmgr.WithTraceReporter(str),
)
if err != nil {
Expand All @@ -109,14 +116,14 @@
lp2pconnmgr.WithGracePeriod(time.Minute),
)
if err != nil {
return nil, LibP2PError{Err: err}

Check warning on line 119 in network/network.go

View check run for this annotation

Codecov / codecov/patch

network/network.go#L119

Added line #L119 was not covered by tests
}

opts = append(opts,
lp2p.Identity(networkKey),
lp2p.ListenAddrStrings(conf.Listens...),
lp2p.UserAgent(version.Agent()),
lp2p.ResourceManager(rmgr),
lp2p.ResourceManager(resMgr),
lp2p.ConnectionManager(connMgr),
)

Expand Down
4 changes: 2 additions & 2 deletions network/notifee.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func (n *NotifeeService) Connected(lp2pn lp2pnetwork.Network, conn lp2pnetwork.C
peerID := conn.RemotePeer()

go func() {
for i := 0; i < 6; i++ {
for i := 0; i < 10; i++ {
// TODO: better way?
// Wait to complete libp2p identify
time.Sleep(200 * time.Millisecond)
time.Sleep(500 * time.Millisecond)

protocols, _ := lp2pn.Peerstore().SupportsProtocols(peerID, n.protocolID)
if len(protocols) > 0 {
Expand Down
Loading