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

feat(p2p): grow MaxPeers with # of subnets #1923

Merged
merged 22 commits into from
Dec 11, 2024
Merged

Conversation

nkryuchkov
Copy link
Contributor

@nkryuchkov nkryuchkov commented Dec 5, 2024

We have noticed public operators with a lot of subnets having hard time to fill peers into all their subnets, having connectivity issues at the end making them miss duties

Since some of them may have configured max peers to the current default value (60), changing the default config value is not enough. Therefore, we need some workaround like this PR

However, we'll need to come up with a more elegant solution later

This PR is meant to be an alternative (simpler) temporary solution in case we decide not to proceed with #1917 and #1919 right now

@nkryuchkov nkryuchkov requested a review from y0sher December 5, 2024 14:19
@nkryuchkov nkryuchkov requested a review from iurii-ssv December 5, 2024 14:59
@nkryuchkov nkryuchkov requested a review from moshe-blox December 5, 2024 19:12
@y0sher
Copy link
Contributor

y0sher commented Dec 8, 2024

Adding here this data @nkryuchkov collected about the committees per operator distribution in mainnet network, this should us as a reference for deciding on the parameters of this change:

% of operators with >0 committees is 100.00
% of operators with >1 committees is 19.83
% of operators with >2 committees is 11.33
% of operators with >3 committees is 9.17
% of operators with >4 committees is 8.17
% of operators with >5 committees is 7.33
% of operators with >6 committees is 6.83
% of operators with >7 committees is 6.83
% of operators with >8 committees is 6.50
% of operators with >9 committees is 6.33
% of operators with >10 committees is 6.17

* wip

* subnets instead of committees

* fix
@moshe-blox moshe-blox changed the title p2p: increase configured max peers if operator has many committees feat(p2p): grow MaxPeers with # of subnets Dec 9, 2024
@moshe-blox
Copy link
Contributor

added new log for topic peers distribution:

{"topic peers distribution","min":2,"median":5,"max":7,"dead_subnets":0,"unhealthy_subnets":1}

Copy link
Contributor

@y0sher y0sher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. adding proof it works:
image

start := time.Now()
myValidators := nodeStorage.ValidatorStore().OperatorValidators(operatorData.ID)
mySubnets := make(records.Subnets, networkcommons.SubnetsCount)
myActiveSubnets := 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just replace myActiveSubnets with len(mySubnets) ?

cli/operator/node.go Outdated Show resolved Hide resolved
myActiveSubnets++
}
}
idealMaxPeers := min(baseMaxPeers+peersPerSubnet*myActiveSubnets, maxPeersLimit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't idealMaxPeers be instead something like this ?

idealMaxPeers := min(max(baseMaxPeers, peersPerSubnet*myActiveSubnets), maxPeersLimit)

If we have 52 active subnets baseMaxPeers+peersPerSubnet*myActiveSubnets would be = 60 + 52*3 which is way too high, no ?

Copy link
Contributor

@moshe-blox moshe-blox Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tested with only 16 subnets and 60 peers is not enough (but 80-90 is), so instead we keep the minimum of 60 + add more for every subnet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tested with only 16 subnets and 60 peers is not enough (but 80-90 is), so instead we keep the minimum of 60 + add more for every subnet

ah, I see

}
}

func (n *p2pNetwork) reportTopicPeers(logger *zap.Logger, name string) {
func (n *p2pNetwork) reportTopicPeers(logger *zap.Logger, name string) (peerCount int) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be simpler to get rid of this func completely (inline it) because currently we have this measuring/reporting/logging code partially here, partially there

Comment on lines 360 to 368
if cfg.P2pNetworkConfig.MaxPeers < idealMaxPeers {
logger.Warn("increasing MaxPeers to match the operator's subscribed subnets",
zap.Int("old_max_peers", cfg.P2pNetworkConfig.MaxPeers),
zap.Int("new_max_peers", idealMaxPeers),
zap.Int("subscribed_subnets", myActiveSubnets),
zap.Duration("took", time.Since(start)),
)
cfg.P2pNetworkConfig.MaxPeers = idealMaxPeers
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need to even have cfg.P2pNetworkConfig.MaxPeers value now if we are gonna overwrite it in most cases anyway ? Perhaps we want to remove it to keep it simple (otherwise later on we/somebody might wrongly think the MaxPeers value he sets in config file is the value that's gonna be used - which is not gonna be the case).

Copy link
Contributor

@moshe-blox moshe-blox Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a temporary solution and we wouldnt want to educate everyone about a new configuration change only to take it down very soon after

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although we could potentially rename it to TargetPeers and just leave it as is even if we end up reverting this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iurii-ssv i made some changes to make it more clear that MaxPeers is currently not the max

@moshe-blox moshe-blox merged commit 1fea2e2 into stage Dec 11, 2024
5 checks passed
@moshe-blox moshe-blox deleted the more-committees-more-peers branch December 11, 2024 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants