From 6c3cb99d6d575d975105e05d4b1bbb2a3ea42980 Mon Sep 17 00:00:00 2001 From: yacovm Date: Tue, 4 Jul 2017 14:04:10 +0300 Subject: [PATCH] [FAB-5157] Optimize peer selection of channel batches In gossip whenever a batch of channel-scoped messages (either leadership, blocks, stateInfo, etc.) is sent to remote peers, a function goes over all existing alive peers and then selects from them a subset of peers. This is done in gossipInChan function In case of leadership messages, the subset is taken from the entire membership set without an upper bound (we gossip leadership messages to all peers in the channel), and in case of non-leadership messages the subset is taken with an upper bound equal to the propogation fanout (configurable). Finding peers that are eligible to receive any channel-related data involves cryptographical computations and is non-negligible (measured ~ 25ms in a network of 8 peers) The 2 possibilities (leadership and non-leadership) are calculated even though each method invocation of gossipInChan receives only 1 type of message. Therefore, it would be beneficial performance wise to just calculate the option that is relevant to that method invocation and not calculate both options each time. This commit addresses this by calculating the peers to send according to the type of message in the invocation. Change-Id: If6940182f83ef046c1d1f7186a71946128591e69 Signed-off-by: yacovm --- gossip/gossip/gossip_impl.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gossip/gossip/gossip_impl.go b/gossip/gossip/gossip_impl.go index 6f1d35dce88..da317819a74 100644 --- a/gossip/gossip/gossip_impl.go +++ b/gossip/gossip/gossip_impl.go @@ -595,6 +595,9 @@ func (g *gossipServiceImpl) gossipInChan(messages []*proto.SignedGossipMessage, return bytes.Equal(o.(*proto.SignedGossipMessage).Channel, channel) } messagesOfChannel, messages = partitionMessages(grabMsgs, messages) + if len(messagesOfChannel) == 0 { + continue + } // Grab channel object for that channel gc := g.chanState.getGossipChannelByChainID(channel) if gc == nil { @@ -604,15 +607,16 @@ func (g *gossipServiceImpl) gossipInChan(messages []*proto.SignedGossipMessage, // Select the peers to send the messages to // For leadership messages we will select all peers that pass routing factory - e.g. all peers in channel and org membership := g.disc.GetMembership() - allPeersInCh := filter.SelectPeers(len(membership), membership, chanRoutingFactory(gc)) - peers2Send := filter.SelectPeers(g.conf.PropagatePeerNum, membership, chanRoutingFactory(gc)) + var peers2Send []*comm.RemotePeer + if messagesOfChannel[0].IsLeadershipMsg() { + peers2Send = filter.SelectPeers(len(membership), membership, chanRoutingFactory(gc)) + } else { + peers2Send = filter.SelectPeers(g.conf.PropagatePeerNum, membership, chanRoutingFactory(gc)) + } + // Send the messages to the remote peers for _, msg := range messagesOfChannel { - if msg.IsLeadershipMsg() { - g.comm.Send(msg, allPeersInCh...) - } else { - g.comm.Send(msg, peers2Send...) - } + g.comm.Send(msg, peers2Send...) } } }