Merge pull request #3727 from nspcc-dev/network-optimaln

network: optimize optimalN for small networks
This commit is contained in:
Anna Shaleva 2024-12-05 23:26:41 +03:00 committed by GitHub
commit 1aed0faeec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -482,7 +482,7 @@ func (s *Server) run() {
var ( var (
netSize = s.discovery.NetworkSize() netSize = s.discovery.NetworkSize()
// "Optimal" number of peers. // "Optimal" number of peers.
optimalN = s.discovery.GetFanOut() * 2 optimalN = min(s.discovery.GetFanOut()*2, netSize-1)
// Real number of peers. // Real number of peers.
peerN = s.HandshakedPeersCount() peerN = s.HandshakedPeersCount()
// Timeout value for the next peerTimer, long one by default. // Timeout value for the next peerTimer, long one by default.
@ -494,7 +494,7 @@ func (s *Server) run() {
s.discovery.RequestRemote(s.AttemptConnPeers) s.discovery.RequestRemote(s.AttemptConnPeers)
// Check/retry new connections soon. // Check/retry new connections soon.
peerT = s.ProtoTickInterval peerT = s.ProtoTickInterval
} else if s.MinPeers > 0 && loopCnt%s.MinPeers == 0 && optimalN > peerN && optimalN < s.MaxPeers && optimalN < netSize { } else if s.MinPeers > 0 && loopCnt%s.MinPeers == 0 && optimalN > peerN && optimalN < s.MaxPeers {
// Having some number of peers, but probably can get some more, the network is big. // Having some number of peers, but probably can get some more, the network is big.
// It also allows to start picking up new peers proactively, before we suddenly have <s.MinPeers of them. // It also allows to start picking up new peers proactively, before we suddenly have <s.MinPeers of them.
s.discovery.RequestRemote(min(s.AttemptConnPeers, optimalN-peerN)) s.discovery.RequestRemote(min(s.AttemptConnPeers, optimalN-peerN))