-
Notifications
You must be signed in to change notification settings - Fork 225
feat : Implement slot-based MGET batching for cluster clients #908
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?
feat : Implement slot-based MGET batching for cluster clients #908
Conversation
Implement slot-based MGET batching for cluster clients Co-authored-by: SoulPancake <[email protected]>
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
rueian
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.
Functionally, it works, but can we optimize allocations?
|
I optimised the slice mem allocation, is there any other potential improvement I can work on? @rueian |
I wonder if it is possible to avoid using |
@rueian |
|
|
I have some trouble will my personal laptop, I will address these in a week approx, hope that is okay |
Co-authored-by: Rueian <[email protected]>
Co-authored-by: Rueian <[email protected]>
32627b2 to
39a9e9f
Compare
|
@rueian
|
|
Hi @rueian Any chance to review this? |
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.
❌ The following Jit checks failed to run:
- secret-detection-trufflehog
#jit_bypass_commit in this PR to bypass, Jit Admin privileges required.
More info in the Jit platform.
helper.go
Outdated
| slotCount := make(map[uint16]int, len(keys)/2) | ||
| for _, key := range keys { | ||
| slotCount[slot(key)]++ | ||
| } | ||
| cmds := mgetcmdsp.Get(0, len(slotCount)) | ||
| defer mgetcmdsp.Put(cmds) | ||
| for s := range slotCount { | ||
| var builder any = client.B().Mget() | ||
| var first = true | ||
| for _, key := range keys { | ||
| if slot(key) == s { | ||
| if first { | ||
| builder = builder.(intl.Mget).Key(key) | ||
| first = false | ||
| } else { | ||
| builder = builder.(intl.MgetKey).Key(key) | ||
| } | ||
| } | ||
| } | ||
| cmds.s = append(cmds.s, builder.(intl.MgetKey).Build().Pin()) |
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.
Hi @SoulPancake,
Right now, you count the number of keys for each slot, but then discard them, and then iterate over the whole keys slice for each slot, which I think is super inefficient.
How about storing the resulting indexes of cmd.s to the map[uint16]int map first? As I said previously. So that you can use slot(key) to locate the index of cmds.s and only iterate the keys slice twice in total.
| } | ||
|
|
||
| slotIdx := make(map[uint16]int, len(keys)/2) | ||
| var builders []any |
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.
| var builders []any | |
| cmds := mgetcmdsp.Get(0, len(keys)) | |
| defer mgetcmdsp.Put(cmds) |
Again, we should avoid additional allocations. This builders []any can be replaced by the cmds.s
For #844