server: optimize message broadcast+targeted send

This commit slightly optimizes the process of broadcasting a message to
a list of peers, and also sending a set of messages to a target peer.

When broadcasting a message to a set of target peers, we now launch a
goroutine for each send as to not block the ChannelRouter on an
individual send. When sending a set of messages to a target peer, we
now give up the mutex as soon as we’ve access the map, rather than
holding onto it until the sending is complete.
This commit is contained in:
Olaoluwa Osuntokun committed 2017-01-29 15:03:05 -08:00
1 parent d94777acf6
commit 1ee4c661bc
3 files changed
+9 -4

No files matched your search

+6 -4
View File
@@ -594,9 +594,11 @@ out:
continue
}
for _, msg := range bMsg.msgs {
peer.queueMsg(msg, nil)
}
go func() {
for _, msg := range bMsg.msgs {
peer.queueMsg(msg, nil)
}
}()
}
s.peersMtx.RUnlock()
@@ -624,11 +626,11 @@ out:
sMsg.errChan <- errors.New("peer not found")
return
}
s.peersMtx.RUnlock()
for _, msg := range sMsg.msgs {
targetPeer.queueMsg(msg, nil)
}
s.peersMtx.RUnlock()
sMsg.errChan <- nil
}()