-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gossip: avoid allocation of UnresolvedAddr in getNodeIDAddressLocked #29585
gossip: avoid allocation of UnresolvedAddr in getNodeIDAddressLocked #29585
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale)
pkg/gossip/gossip.go, line 1003 at r1 (raw file):
return nil, err } for i, locality := range nd.LocalityAddress {
Nit: we could kill both birds with one stone by removing the locality
variable here and defining it as a pointer inside of the loop:
for i := range nd.LocalityAddress {
locality := &nd.LocalityAddress[i]
}
384cc2a
to
9d226a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors r+
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale)
pkg/gossip/gossip.go, line 1003 at r1 (raw file):
Previously, petermattis (Peter Mattis) wrote…
Nit: we could kill both birds with one stone by removing the
locality
variable here and defining it as a pointer inside of the loop:for i := range nd.LocalityAddress { locality := &nd.LocalityAddress[i] }
Good idea, done.
`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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying that this removed allocations on a cluster that wasn't even using locality-scoped addresses?
29574: storage: update import path for Raft r=petermattis a=tschottdorf upstream moved from github.com/etcd to go.etcd.io/etcd. We're going to have to pick up an update soon to fix #28918, so it's easier to switch now. We're not picking up any new commits except for the renames. Release note: None 29585: gossip: avoid allocation of UnresolvedAddr in getNodeIDAddressLocked r=nvanbenschoten a=nvanbenschoten `getNodeIDAddressLocked` is called from `Dialer.ConnHealth` and `Dialer.DialInternalClient`. It was responsible for **1.71%** of all allocations (`alloc_objects`) 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. Co-authored-by: Tobias Schottdorf <[email protected]> Co-authored-by: Nathan VanBenschoten <[email protected]>
Build succeeded |
@a-robinson and I took this conversation offline and figured out what was going on. It turns out that even when a loop is never entered, if its loop variable escapes and is moved to the heap then it will result in an allocation. We can see this in the following assembly (with some added comments for ease of reading).
We also noticed that this |
getNodeIDAddressLocked
is called fromDialer.ConnHealth
andDialer.DialInternalClient
. It was responsible for 1.71% of allallocations (
alloc_objects
) on a 3-node long-running cluster thatwas running TPC-C 1K.
Pointing into
nd.LocalityAddress
is safe because even if theNodeDescriptor
itself is replaced in
Gossip
, the struct is never internally mutated. This isthe same reason why taking the address of
nd.Address
was already safe.Release note (performance improvement): Avoid allocation when
checking RPC connection health.