-
Notifications
You must be signed in to change notification settings - Fork 985
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
Performance: Encoding of keys/values in CommandArgs when using a codec that implements ToByteBufEncoder #2610
Comments
i.e. Seems pretty simple:
If somehow we miss releasing to the netty Again happy to contribute and will create a separate issue if the optimisation makes sense Setup Details
node: m6gd.xlarge ec2 nodes
|
Have done a crudish untested version of the changes needed, if project owners agree then will add a more formal version in separate PRs |
Thanks for looking into this. We follow this approach to ensure protocol compliance by creating the encoded representation first and then write the correct byte size to the argument buff. It could make sense to introduce the optimization in the form that Regarding the In any case, before we proceed with code changes, it would be good to have some measurements before and after such changes to learn how much of an impact such a change provides. |
Thanks, the preallocated Stack makes good sense. |
Let's go with a single pull request that has two commits for easier reviewing. |
Just curious though, where does the number 32 comes from, like why won't we ever need more than that? |
32 is an estimate of Redis' response depth (array-in-array-in-object-…). Most commands key/value commands have single-depth while some extended Stream commands (such as XPENDING) have a nesting level of 6. I think that even 16 should be fine, but 32 brings us more on the safe side. |
Got it, Thanks. |
Hey, I have been caught up in some work last 2 weeks. Will do it this week and send a PR around the end. |
…te object allocs redis#2610 * adds gc and thrpt profiling in RedisStateMachine benchmark * fixes a stale benchmark which caused compilation errors ClusterDistributionChannelWriterBenchmark
…redis#2610 * adds benchmarks to show perf gains * about 10x improvement in perf, with no added gc overhead
Thanks a lot, this was a decent improvement. |
Thanks, any chance of a release soon which includes these? |
6.3.2.RELEASE is scheduled for March 15 |
Feature Request
Remove unwanted allocation when encoding
CommandArgs
when using a codec of typeToByteBufEncoder
Is your feature request related to a problem? Please describe
I was analysing cpu/memory for a jvm server that uses Redis heavily (order of 10s of thousands hmget/sec on ~10 connections) and noticed a good amount of CPU usage of the VM (~30% of total and ~70% of eventloops cpu time) comes from
CommandArgs.KeyArgument.encode
All the connections use a ByteArrayCodec. Majority of the time is basically Netty's bytebuf gc/pooling logic.
The reason seems to be our specific usecase where every hmget call has 100s of keys and this gets called for each key
I looked through the implementation and it felt like these allocs can be entirely avoided for the special case where user does all req/resp in byte arrays (like folks who use the ByteArrayCodec) or for users who can exactly estimate the size of key/val
Two disclaimers:
Describe the solution you'd like
Relevant code is in
CommandArgs.KeyArgument.encode()
andCommandArgs.ValueArgument.encode()
The solution will be replacing above with something like:
Now this has a caveat because of which I'm creating this issue, It assumes estimatedSize is not "estimated" but "exact".
Maybe we can give user the control by adding another method in ToByteBufEncoder which can tell us if the codec can predict exact sizes.
In ByteArrayCodec we always can.
This ensures no additional allocs and essentially makes it garbage free.
Happy to contribute and impl the solution.
Describe alternatives you've considered
Teachability, Documentation, Adoption, Migration Strategy
NA
The text was updated successfully, but these errors were encountered: