Skip to content

Commit

Permalink
[FAB-5157] Optimize peer selection of channel batches
Browse files Browse the repository at this point in the history
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 <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Jul 4, 2017
1 parent b8e189e commit 6c3cb99
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions gossip/gossip/gossip_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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...)
}
}
}
Expand Down

0 comments on commit 6c3cb99

Please sign in to comment.