Skip to content

Commit

Permalink
gossip: avoid allocation of UnresolvedAddr in getNodeIDAddressLocked
Browse files Browse the repository at this point in the history
`getNodeIDAddressLocked` is called from `Dialer.ConnHealth` and
`Dialer.DialInternalClient`. It was responsible for 1.71% of all
allocations on a 3-node long running cluster that was running TPC-C 1K.

Pointing into `nd.LocalityAddress` is safe because even if the `NodeDescriptor`
itself is replaced in `Gossip`, the struct is never internally mutated. This is
the same reason why taking the address of `nd.Address` was already safe.

Release note (performance improvement): Avoid allocation when
checking RPC connection health.
  • Loading branch information
nvanbenschoten committed Sep 5, 2018
1 parent 1571818 commit 384cc2a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/gossip/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,13 +1000,12 @@ func (g *Gossip) getNodeIDAddressLocked(nodeID roachpb.NodeID) (*util.Unresolved
if err != nil {
return nil, err
}
address := &nd.Address
for _, locality := range nd.LocalityAddress {
for i, locality := range nd.LocalityAddress {
if _, ok := g.localityTierMap[locality.LocalityTier.String()]; ok {
return &locality.Address, nil
return &nd.LocalityAddress[i].Address, nil
}
}
return address, nil
return &nd.Address, nil
}

// AddInfo adds or updates an info object. Returns an error if info
Expand Down

0 comments on commit 384cc2a

Please sign in to comment.