-
Notifications
You must be signed in to change notification settings - Fork 226
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 <70265851+SoulPancake@users.noreply.github.com>
|
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 <rueiancsie@gmail.com>
Co-authored-by: Rueian <rueiancsie@gmail.com>
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.
Co-authored-by: Rueian <rueiancsie@gmail.com>
| resps := client.DoMulti(ctx, cmds.s...) | ||
| defer resultsp.Put(&redisresults{s: resps}) | ||
|
|
||
| values := make([][]RedisMessage, len(cmds.s)) |
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 @rueian
Sorry I've been caught up with other things and missed focused work on this
Do you think this allocation is still alright?
I cannot think of a better way for this
| defer resultsp.Put(&redisresults{s: resps}) | ||
|
|
||
| // Convert each response to an array once | ||
| values := make([][]RedisMessage, len(cmds.s)) |
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.
only using:
- slotIdx map[uint16]int for slot → command index, and
- the pooled cmds.s slice for the actual Completed commands.
For #844