Skip to content

Commit

Permalink
chore(networ): log-scale for network limit
Browse files Browse the repository at this point in the history
  • Loading branch information
themantre committed Oct 24, 2023
1 parent a1c9ec1 commit 3c934ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ func newNetwork(networkName string, conf *Config, opts []lp2p.Option) (*network,
return nil, LibP2PError{Err: err}
}

maxconns := conf.MaxConns
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)
changes.System.ConnsInbound = lp2prcmgr.LimitVal(logScale(maxConns))
changes.System.ConnsOutbound = lp2prcmgr.LimitVal(logScale(maxConns))
changes.System.Conns = lp2prcmgr.LimitVal(logScale(2 * maxConns))
limit := changes.Build(lp2prcmgr.DefaultLimits.AutoScale())

resMgr, err := lp2prcmgr.NewResourceManager(
Expand Down
6 changes: 6 additions & 0 deletions network/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package network

import (
"context"
"math/bits"
"time"

lp2phost "github.com/libp2p/go-libp2p/core/host"
Expand Down Expand Up @@ -57,3 +58,8 @@ func ConnectAsync(ctx context.Context, h lp2phost.Host, addrInfo lp2ppeer.AddrIn
}
}()
}

func logScale(val int) int {
bitlen := bits.Len(uint(val))
return 1 << bitlen
}

0 comments on commit 3c934ef

Please sign in to comment.