-
Notifications
You must be signed in to change notification settings - Fork 512
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
streaming store-gateway: avoid copying postings when hashing them #3779
Conversation
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
pkg/storegateway/indexcache/cache.go
Outdated
byteSlice := make([]byte, 0) | ||
slicePtr := (*reflect.SliceHeader)(unsafe.Pointer(&byteSlice)) | ||
slicePtr.Data = (*reflect.SliceHeader)(unsafe.Pointer(&postings)).Data | ||
slicePtr.Len = len(postings) * 8 |
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, non blocking] Instead of hardcoding 8
, can we read the size of storage.SeriesRef
instead?
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.
yeah i thought about that but the tradeoff was using the unsafe
package more 😄
i did the change in e57efad, see what you think
These are the results of running
|
Remember to add the PR number to the existing CHANGELOG entry. |
I'm wondering if we could also have a simple unit test on |
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
pkg/storegateway/indexcache/cache.go
Outdated
|
||
return PostingsKey(base64.RawURLEncoding.EncodeToString(checksum)) | ||
const bytesPerPosting = int(unsafe.Sizeof(storage.SeriesRef(0)) / unsafe.Sizeof(byte(0))) |
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.
I hope the size of 1 byte won't change :D
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.
yeah fair. we have the go 1.x guarantee 😄
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!
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
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, just a few small non-blocking things.
Co-authored-by: Nick Pillitteri <56quarters@users.noreply.github.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-3779-to-r217 origin/r217
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x 4f73f285aaadb5046a9fb8be8217b2d0f934e598
# Push it to GitHub
git push --set-upstream origin backport-3779-to-r217
git switch main
# Remove the local backport branch
git branch -D backport-3779-to-r217 Then, create a pull request where the |
) This PR solves two problems: a bug I just discovered - when we previously constructed the byte slice of the postings we were incorrectly setting the byte position of the octet from the posting it was hashable[i+octet] = byte(posting >> (octet * 8)) it should be hashable[i*8+octet] = byte(posting >> (octet * 8)) avoids copying the postings into a byte slice altogether. Instead, it creates a new sliceHeader that it points to the data of the postings and adjusts the length and capacity. It also changes the hashing functions from SHA1 (20B) + Blake2 (32B) to only Blake2 (32B). The memcached cache key is too small to fit both SHA1 and Blake2. In another change that will also remove the matchers hash from the key I will use Blake2 with 42B (cherry picked from commit 4f73f28)
This PR solves two problems:
It also changes the hashing functions from SHA1 (20B) + Blake2 (32B) to only Blake2 (32B). The memcached cache key is too small to fit both SHA1 and Blake2. In another change that will also remove the matchers hash from the key I will use Blake2 with 42B