refactor: go straight to PeerCache for fetching topology
There is no need to go via Topology. Fetching does not access or modify the Topology state, and none of the functions on Topology update the PeerCache. So there is no point serialising the fetching with RebuildRoutes (or anything else). This does mean the connections' receiveTCP goroutines will take a direct lock on PeerCache, but a) it is only a read lock, and b) they already take a write lock in another code path. There may be some extra load on the PeerCache as a result of this change, due to the topology fetching of multiple connections no longer being funneled through the single Topology goroutine. Consequently, write locks on the PeerCache may take a little longer to acquire. Until we encounter this as a genuine problem though it's better to stick with the simpler code.
This commit is contained in:
1 parent
aa5fc62184
commit
fc1ec6ada2
2 files changed
+1
-13
No files matched your search
@@ -493,7 +493,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder, usingPassword bool
|
||||
// the payload are not included
|
||||
// - elements where the payload was older than the
|
||||
// receiver's version are updated
|
||||
conn.SendTCP(Concat(ProtocolUpdateByte, conn.Router.Topology.FetchAll()))
|
||||
conn.SendTCP(Concat(ProtocolUpdateByte, conn.Router.Peers.EncodeAllPeers()))
|
||||
} else if msg[0] == ProtocolUpdate {
|
||||
newUpdate, err := conn.Router.Peers.ApplyUpdate(msg[1:], conn.Router)
|
||||
if _, ok := err.(UnknownPeersError); err != nil && ok {
|
||||
|
||||
@@ -54,19 +54,9 @@ func StartTopology(router *Router) *Topology {
|
||||
// ACTOR client API
|
||||
|
||||
const (
|
||||
TFetchAll = iota
|
||||
TRebuildRoutes = iota
|
||||
)
|
||||
|
||||
func (topo *Topology) FetchAll() []byte {
|
||||
resultChan := make(chan interface{}, 0)
|
||||
topo.queryChan <- &Interaction{
|
||||
code: TFetchAll,
|
||||
resultChan: resultChan}
|
||||
result := <-resultChan
|
||||
return result.([]byte)
|
||||
}
|
||||
|
||||
// Async.
|
||||
func (topo *Topology) RebuildRoutes() {
|
||||
topo.queryChan <- &Interaction{code: TRebuildRoutes}
|
||||
@@ -88,8 +78,6 @@ func (topo *Topology) queryLoop(queryChan <-chan *Interaction) {
|
||||
topo.unicast = unicast
|
||||
topo.broadcast = broadcast
|
||||
topo.Unlock()
|
||||
case TFetchAll:
|
||||
query.resultChan <- topo.router.Peers.EncodeAllPeers()
|
||||
default:
|
||||
log.Fatal("Unexpected topology query:", query)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user