EOSIO / eos

An open source smart contract platform
https://developers.eos.io/manuals/eos
MIT License
11.28k stars 3.6k forks source link

Limit outgoing p2p connections #8170

Open matthewdarwin opened 4 years ago

matthewdarwin commented 4 years ago

I seem to remember some discussion in the past where there is some optimal number of p2p connections nodeos should have. However, the world is a messy place, so I might want to have lots of p2p connections specified in my config.ini so that when there are failures, it will connect to another one. But then that is inefficient if they are all working.

So what about a config option that is max-outgoing-connections=x, so I can specify how many outgoing connections to allow. My config.ini might have many more than 'x' defined, but nodeos will stop trying to connect to more peers once 'x' has been 'successfully' reached. (invalid peers are bypassed).

This option might be enabled by default so people who are not experts don't have to worry about tuning the number of connections.

Background: Block Producers allow many incoming connections to improve peering. EOS Nation gets over 700 inbound connections on EOS Mainnet (there are reports of other top technical BPs having more than 400). If the general public is just adding the top 30 voted producers in config.ini then this is probably wasting resources by having too many concurrent connections. Better for general public to have minimal number of connections at at time. This will save load for the BPs.

matthewdarwin commented 4 years ago

See also jungle telegram chat from today:

From EOSUSA Micheal:

so backstory: some of us were discussing the p2p protocol and its....well, shortcomings. long story short, im trying to figure out a way i can cut down on all my external p2p reqs from all my nodes but not orphan myself from the chain if a single relay node goes out. so my first thought was to use a proxy for peering so i could control all my internal points and also roll to outside nodes if the internal ones are unavailable. but im curious if theres a way to control the peers like primary and then if those are unavailable , then hit secondary (which would be externals). ive just got 3+ nodes for most chains and im pulling like 25mbit steady from just my outbound p2p traffic but know much of it is the same info ove rand ove rand over again

cc32d9 commented 4 years ago

few more ideas as discussed in Wax guilds chat:

there need to be 3 categories of peers in the configuration:

  1. Primary peers: the node is always trying to connect to them.

  2. Backup peers: the node connects to them if none of primary ones are available.

  3. Pool peers: a relatively high number of endpoints, and only a limited subset of it is utilized, according to maximum outgoing connections parameter. The node should pick them randomly, in order to even out the load on public p2p service.

cc32d9 commented 4 years ago

probably it's enough to have only primary and pool peers. The backup peers seem to add unnecessary complexity.

The configuration would go like this:

# these will always try to connect
p2p-primary-peer-address = internalhost.mydomain.com:9876

# pool peers inherit the old config statement
p2p-peer-address = bp.cryptolions.io:9876

# maximum number of pool peers to connect. default should be something reasonable, maybe 5
max-outgoing-p2p-connections = 5
scottoau commented 4 years ago

+1. This would be a very useful addition to config options.