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
Reduce memory allocations during endpoint restore #12405
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The GetCiliumVersionString function is only used in a single function within this package. Move it where it is used to reduce the package size of pkg/common which is imported all over the place. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
The way endpoint state currently is restored from header files could potentially lead to a lot of memory allocations, partially due to the fact that the respective base64 encoded state is converted to a string after being read and then converted back to a byte slice in order to decode it. Since every conversion of a byte slice to a string allocates (due to the fact that strings are immutable in Go), this essentially doubles the memory that is used which could lead to memory allocation spikes during restore. Avoid this by reading the base64 encoded endpoint state into a byte slice directly and thus reducing the size and number of allocations. Before: EndpointSuite.BenchmarkReadEPsFromDirNames 5000 399980 ns/op 83665 B/op 743 allocs/op After: EndpointSuite.BenchmarkReadEPsFromDirNames 5000 369643 ns/op 73479 B/op 731 allocs/op Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
tklauser
added
kind/performance
There is a performance impact of this.
release-note/misc
This PR makes changes that have no direct user impact.
labels
Jul 3, 2020
test-me-please |
aanm
approved these changes
Jul 3, 2020
ianvernon
approved these changes
Jul 3, 2020
christarazi
approved these changes
Jul 4, 2020
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.
Nice!
pchaigno
approved these changes
Jul 6, 2020
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.
Nice catch!
maintainer-s-little-helper
bot
added
the
ready-to-merge
This PR has passed all tests and received consensus from code owners to merge.
label
Jul 6, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kind/performance
There is a performance impact of this.
ready-to-merge
This PR has passed all tests and received consensus from code owners to merge.
release-note/misc
This PR makes changes that have no direct user impact.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First commit is preparatory and moves a function from
pkg/common
into
pkg/endpoint
which is only used there.Second commit avoids excessive allocations during endpoint restore:
The way endpoint state currently is restored from header files could
potentially lead to a lot of memory allocations, partially due to the fact
that the respective base64 encoded state is converted to a string after
being read and then converted back to a byte slice in order to decode
it. Since every conversion of a byte slice to a string allocates (due to
the fact that strings are immutable in Go), this essentially doubles the
memory that is used which could lead to memory allocation spikes during
restore.
Avoid this by reading the base64 encoded endpoint state into a
byte slice directly and thus reducing the size and number of
allocations.
Before:
After:
For #12367 to slightly reduce chances of OOM.