Skip to content

Commit 6c3cb99

Browse files
committed
[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 <[email protected]>
1 parent b8e189e commit 6c3cb99

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

gossip/gossip/gossip_impl.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ func (g *gossipServiceImpl) gossipInChan(messages []*proto.SignedGossipMessage,
595595
return bytes.Equal(o.(*proto.SignedGossipMessage).Channel, channel)
596596
}
597597
messagesOfChannel, messages = partitionMessages(grabMsgs, messages)
598+
if len(messagesOfChannel) == 0 {
599+
continue
600+
}
598601
// Grab channel object for that channel
599602
gc := g.chanState.getGossipChannelByChainID(channel)
600603
if gc == nil {
@@ -604,15 +607,16 @@ func (g *gossipServiceImpl) gossipInChan(messages []*proto.SignedGossipMessage,
604607
// Select the peers to send the messages to
605608
// For leadership messages we will select all peers that pass routing factory - e.g. all peers in channel and org
606609
membership := g.disc.GetMembership()
607-
allPeersInCh := filter.SelectPeers(len(membership), membership, chanRoutingFactory(gc))
608-
peers2Send := filter.SelectPeers(g.conf.PropagatePeerNum, membership, chanRoutingFactory(gc))
610+
var peers2Send []*comm.RemotePeer
611+
if messagesOfChannel[0].IsLeadershipMsg() {
612+
peers2Send = filter.SelectPeers(len(membership), membership, chanRoutingFactory(gc))
613+
} else {
614+
peers2Send = filter.SelectPeers(g.conf.PropagatePeerNum, membership, chanRoutingFactory(gc))
615+
}
616+
609617
// Send the messages to the remote peers
610618
for _, msg := range messagesOfChannel {
611-
if msg.IsLeadershipMsg() {
612-
g.comm.Send(msg, allPeersInCh...)
613-
} else {
614-
g.comm.Send(msg, peers2Send...)
615-
}
619+
g.comm.Send(msg, peers2Send...)
616620
}
617621
}
618622
}

0 commit comments

Comments
 (0)