mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +00:00
network: randomize peer iteration order
While iterating over map in getPeers() is non-deterministic it's not really random enough for our purposes (usually maps have 2-3 paths through them), we need to fill our peers queues more uniformly. Believe it or not, but it does affect performance metrics, baseline (four nodes, 10 workers): RPS ≈ 7791.675 7996.559 7834.504 7746.705 7891.614 ≈ 7852 ± 1.10% TPS ≈ 7241.497 7711.765 7520.211 7425.890 7334.443 ≈ 7447 ± 2.17% CPU % 29.853 39.936 39.945 36.371 39.999 ≈ 37.2 ± 10.57% Mem MB 2749.635 2791.609 2828.610 2910.431 2863.344 ≈ 2829 ± 1.97% Patched: RPS 8180.760 8137.822 7858.358 7820.011 8051.076 ≈ 8010 ± 2.04% ↑ 2.01% TPS 7819.831 7521.172 7519.023 7242.965 7426.000 ≈ 7506 ± 2.78% ↑ 0.79% CPU % 41.983 38.775 40.606 39.375 35.537 ≈ 39.3 ± 6.15% ↑ 5.65% Mem MB 2947.189 2743.658 2896.688 2813.276 2863.108 ≈ 2853 ± 2.74% ↑ 0.85%
This commit is contained in:
parent
b55c75d59d
commit
d51db20405
1 changed files with 3 additions and 0 deletions
|
@ -1146,6 +1146,9 @@ func (s *Server) iteratePeersWithSendMsg(msg *Message, send func(Peer, bool, []b
|
||||||
if len(peers) == 0 {
|
if len(peers) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
mrand.Shuffle(len(peers), func(i, j int) {
|
||||||
|
peers[i], peers[j] = peers[j], peers[i]
|
||||||
|
})
|
||||||
pkt, err := msg.Bytes()
|
pkt, err := msg.Bytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue