-
Notifications
You must be signed in to change notification settings - Fork 986
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
Optimize aggregation buffer cleanup in CommandHandler #906
Comments
When decode failure, means end with a partial message. Now will just return to continue receive more. if (!decode(ctx, buffer, command)) {
return;
} We should discard the read bytes when end with a partial message. if (!decode(ctx, buffer, command)) {
if (buffer.refCnt() != 0) {
buffer.discardReadBytes();
}
return;
} Maybe we don't need discard read bytes each time when end with a partial message. We can optimize some, like :
|
Thanks for the report. We had early Discarding copies bytes around which can have a performance impact in terms of CPU time. This is a balance between memory cost and CPU cost. Right now, we optimize for CPU. The approach of free percentage seems quite appealing to me. Do you want to give it a spin by submitting a PR that introduces conditional discard after decoding a command? |
Update: That's not exactly a memory leak. A leak causes non-reclaimable memory. This one is rather an optimization to memory usage. |
Sure, Let me try |
Here i pushed a pr on 916 , providing a buffer usage ratio to optimize buffer memory usage. |
I adjusted the ticket title to reflect the actual purpose. |
PR #916 is merged now. Thanks a lot. |
When use pressure test to get data from redis, the redis data value is 16KB. It will cause the out of direct memory.
Saw the source code, I found:
Now the method
decode
inio.lettuce.core.protocol.CommandHandler
will try to decode message received from redis server. When faced partial response message(most under BULK scene), will try to continue receive more and then decode more. While current buffer end with a complete message, it will discard the read bytes.This behavior will keep read bytes always until input buffer end with a complete message. Under my pressure test sense, will always get partial message.
Reproduction setup
-XX:MaxDirectMemorySize=20m
io.lettuce.core.protocol
toDEBUG
Use below test code:
Then the exception occur:
Environment
The text was updated successfully, but these errors were encountered: