Skip to content

Commit

Permalink
Merge pull request #5711 from multiversx/add-resource-limiter-config
Browse files Browse the repository at this point in the history
Add resource limiter config
  • Loading branch information
iulianpascalau authored Nov 16, 2023
2 parents adbd73a + 3cbe775 commit cd89ae9
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cmd/node/config/fullArchiveP2P.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
[Node.Transports.TCP]
ListenAddress = "/ip4/0.0.0.0/tcp/%d" # TCP listen address
PreventPortReuse = false
[Node.ResourceLimiter]
Type = "default autoscale" #available options "default autoscale", "infinite", "default with manual scale".
ManualSystemMemoryInMB = 0 # not taken into account if the type is not "default with manual scale"
ManualMaximumFD = 0 # not taken into account if the type is not "default with manual scale"

# P2P peer discovery section

Expand Down
4 changes: 4 additions & 0 deletions cmd/node/config/p2p.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
[Node.Transports.TCP]
ListenAddress = "/ip4/0.0.0.0/tcp/%d" # TCP listen address
PreventPortReuse = false
[Node.ResourceLimiter]
Type = "default autoscale" #available options "default autoscale", "infinite", "default with manual scale".
ManualSystemMemoryInMB = 0 # not taken into account if the type is not "default with manual scale"
ManualMaximumFD = 0 # not taken into account if the type is not "default with manual scale"

# P2P peer discovery section

Expand Down
4 changes: 4 additions & 0 deletions cmd/seednode/config/p2p.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
[Node.Transports.TCP]
ListenAddress = "/ip4/0.0.0.0/tcp/%d" # TCP listen address
PreventPortReuse = true # seeder nodes will need to enable this option
[Node.ResourceLimiter]
Type = "default with manual scale"
ManualSystemMemoryInMB = 65536 # pretend that the host running the seeder has more RAM so it can handle more connections
ManualMaximumFD = 1048576

# P2P peer discovery section

Expand Down
9 changes: 9 additions & 0 deletions config/tomlConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ func TestP2pConfig(t *testing.T) {
[Node.Transports.TCP]
ListenAddress = "/ip4/0.0.0.0/tcp/%d"
PreventPortReuse = true
[Node.ResourceLimiter]
Type = "default autoscale" #available options "default autoscale", "infinite", "default with manual scale".
ManualSystemMemoryInMB = 1 # not taken into account if the type is not "default with manual scale"
ManualMaximumFD = 2 # not taken into account if the type is not "default with manual scale"
[KadDhtPeerDiscovery]
Enabled = false
Expand Down Expand Up @@ -529,6 +533,11 @@ func TestP2pConfig(t *testing.T) {
WebSocketAddress: "/ip4/0.0.0.0/tcp/%d/ws",
WebTransportAddress: "/ip4/0.0.0.0/udp/%d/quic-v1/webtransport",
},
ResourceLimiter: p2pConfig.P2PResourceLimiterConfig{
Type: "default autoscale",
ManualSystemMemoryInMB: 1,
ManualMaximumFD: 2,
},
},
KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{
ProtocolID: protocolID,
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/google/gops v0.3.18
github.com/gorilla/websocket v1.5.0
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-communication-go v1.0.8
github.com/multiversx/mx-chain-communication-go v1.0.9
github.com/multiversx/mx-chain-core-go v1.2.18
github.com/multiversx/mx-chain-crypto-go v1.2.9
github.com/multiversx/mx-chain-es-indexer-go v1.4.13
Expand All @@ -25,12 +25,14 @@ require (
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.61
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.62
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.90
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
github.com/pelletier/go-toml v1.9.3
github.com/pkg/errors v0.9.1
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/stretchr/testify v1.8.4
github.com/urfave/cli v1.22.10
golang.org/x/crypto v0.10.0
golang.org/x/sys v0.10.0
gopkg.in/go-playground/validator.v8 v8.18.2
)

Expand Down Expand Up @@ -136,7 +138,6 @@ require (
github.com/onsi/ginkgo/v2 v2.9.7 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
Expand Down Expand Up @@ -178,7 +179,6 @@ require (
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/tools v0.9.1 // indirect
gonum.org/v1/gonum v0.11.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n
github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI=
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
github.com/multiversx/mx-chain-communication-go v1.0.8 h1:sTx4Vmx+QCpngUFq/LF/Ka8bevlK2vMxfclE284twfc=
github.com/multiversx/mx-chain-communication-go v1.0.8/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4=
github.com/multiversx/mx-chain-communication-go v1.0.9 h1:unntj9uANJVzANQ4qaE+yth3Y2Tuih6c9ukKAaHOECs=
github.com/multiversx/mx-chain-communication-go v1.0.9/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4=
github.com/multiversx/mx-chain-core-go v1.2.18 h1:fnub2eFL7XYOLrKKVZAPPsaM1TWEnaK5qqY3FLUv168=
github.com/multiversx/mx-chain-core-go v1.2.18/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84=
github.com/multiversx/mx-chain-crypto-go v1.2.9 h1:OEfF2kOQrtzUl273Z3DEcshjlTVUfPpJMd0R0SvTrlU=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func createDefaultConfig() p2pConfig.P2PConfig {
ListenAddress: p2p.LocalHostListenAddrWithIp4AndTcp,
},
},
ResourceLimiter: p2pConfig.P2PResourceLimiterConfig{
Type: p2p.DefaultWithScaleResourceLimiter,
},
},
KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{
Enabled: true,
Expand Down
9 changes: 9 additions & 0 deletions integrationTests/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ func createP2PConfig(initialPeerList []string) p2pConfig.P2PConfig {
ListenAddress: p2p.LocalHostListenAddrWithIp4AndTcp,
},
},
ResourceLimiter: p2pConfig.P2PResourceLimiterConfig{
Type: p2p.DefaultWithScaleResourceLimiter,
},
},
KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{
Enabled: true,
Expand Down Expand Up @@ -237,6 +240,9 @@ func CreateP2PConfigWithNoDiscovery() p2pConfig.P2PConfig {
ListenAddress: p2p.LocalHostListenAddrWithIp4AndTcp,
},
},
ResourceLimiter: p2pConfig.P2PResourceLimiterConfig{
Type: p2p.DefaultWithScaleResourceLimiter,
},
},
KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{
Enabled: false,
Expand Down Expand Up @@ -264,6 +270,9 @@ func CreateMessengerWithNoDiscoveryAndPeersRatingHandler(peersRatingHanlder p2p.
ListenAddress: p2p.LocalHostListenAddrWithIp4AndTcp,
},
},
ResourceLimiter: p2pConfig.P2PResourceLimiterConfig{
Type: p2p.DefaultWithScaleResourceLimiter,
},
},
KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{
Enabled: false,
Expand Down
3 changes: 3 additions & 0 deletions p2p/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type P2PTransportConfig = config.TransportConfig
// P2PTCPTransport will hold the P2P TCP transport config
type P2PTCPTransport = config.TCPProtocolConfig

// P2PResourceLimiterConfig will hold the P2P resource limiter configs
type P2PResourceLimiterConfig = config.ResourceLimiterConfig

// NodeConfig will hold basic p2p settings
type NodeConfig = config.NodeConfig

Expand Down
3 changes: 3 additions & 0 deletions p2p/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ const ConnectionWatcherTypePrint = p2p.ConnectionWatcherTypePrint
// LocalHostListenAddrWithIp4AndTcp defines the local host listening ip v.4 address and TCP
const LocalHostListenAddrWithIp4AndTcp = p2p.LocalHostListenAddrWithIp4AndTcp

// DefaultWithScaleResourceLimiter defines the default & autoscale resource limiter
const DefaultWithScaleResourceLimiter = p2p.DefaultWithScaleResourceLimiter

// BroadcastMethod defines the broadcast method of the message
type BroadcastMethod = p2p.BroadcastMethod
3 changes: 3 additions & 0 deletions testscommon/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ func GetNetworkFactoryArgs() networkComp.NetworkComponentsFactoryArgs {
ListenAddress: p2p.LocalHostListenAddrWithIp4AndTcp,
},
},
ResourceLimiter: p2pConfig.P2PResourceLimiterConfig{
Type: p2p.DefaultWithScaleResourceLimiter,
},
},
KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{
Enabled: false,
Expand Down

0 comments on commit cd89ae9

Please sign in to comment.