-
Notifications
You must be signed in to change notification settings - Fork 2k
state: avoid unnecessary allocation object copies #27311
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
base: main
Are you sure you want to change the base?
Conversation
|
Did a bit more digging on this because I thought perhaps we could get rid of copying Possible solution for reducing the memory footprint of |
jrasell
left a comment
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.
LGTM!
nomad/state/events.go
Outdated
| return structs.Event{}, false | ||
| } | ||
| alloc := after.Copy() | ||
| alloc := after.CopySkipJobAndSanitize() |
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.
Rather than introducing a new method and the flags on the existing methods, could we just move the call to Sanitize() here? That's what the node events do.
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.
right but sanitize copies the whole alloc. We'd ideally skip the Job field. I suppose we could alternatively pass a parameter to Sanitize?
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.
Oh right. There's an existing Allocation.CopySkipJob() method. I suspect we can use that safely in the Sanitize method rather than Allocation.Copy()?
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.
Can we? Allocation.Sanitize() is called in alloc and node RPC endpoints, to return the full allocation object. Wouldn't we want the Job field present there?
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.
CopySkipJob() doesn't nil-out the job, it just doesn't do the deep copy. So in the alloc and node RPC endpoints, we can call Sanitize() and it's safe to keep the pointer to the original copy of the job (because we're not mutating the job). And then here we can call Sanitize and then nil-out the job field (which doesn't touch the original job, just removes the pointer to it).
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.
changed in 0e1c678
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.
tgross
left a comment
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.
LGTM (don't forget the changelog)
While investigating NMD-1105 (possible memory leak in the event stream), I noticed that when we copy allocations, we first call the
Copymethod which returns us a deep copy of the object, and then we remove the job information from it to save space. Afterwards, we sanitize the allocation (i.e., we remove theSignedIdentitiesdata) and during that operation we perform another copy.This changeset doesn't necessarily resolve NMD-1105, but should definitely lower the memory footprint of
eventFromChange.