-
Notifications
You must be signed in to change notification settings - Fork 529
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 postingsCacheKey() memory allocations #4861
Conversation
f4420da
to
6bacfa2
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.
LGTM modulo the test failure (I wasn't able to reproduce locally)
key := make([]byte, expectedLen) | ||
offset := 0 | ||
|
||
offset += copy(key[offset:], prefix) |
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.
nit: this seems very similar to what bytes.Buffer
does
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.
That's true, but I haven't found an easy way to do base64.RawURLEncoding.Encode()
without an extra allocation. Also bytes.Buffer.String()
does an extra allocation too.
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
bee3a9e
to
cff339e
Compare
I'm not sure what's happening, but I noticed that it reports 1 extra allocation when tests run with |
What this PR does
We've observed some high memory allocations in
postingsCacheKey()
andFetchMultiPostings()
in store-gateways, when dealing with thousands or even millions of postings. In particular, under some production workload, we observed 14% CPU taken bypostingsCacheKey()
and 20% CPU taken by the mapassign done byFetchMultiPostings()
:In this PR I'm proposing an optimization to reduce the memory allocations both in
postingsCacheKey()
andFetchMultiPostings()
.Benchmarks:
Note: the size of postings cached in
RemoteIndexCache_FetchMultiPostings
is not realistic (too small) so don't look too much at the memory reduction % there, but allocations reduction is still legit.Which issue(s) this PR fixes or relates to
N/A
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]