Skip to content
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 Netty Frame Decoding #44664

Merged

Conversation

original-brownbear
Copy link
Member

  • We should not create a new wrapper object if there's no bytes in the ByteBuf
  • We should not create a new wrapped ByteBuf if it can't contain a message anyway because it doesn't even have enough bytes for a header left
  • This one is particularly unfortunate right now because for every fully read ByteBuf we still ran the decode loop once again (because of the missing update to continueDecode that I now added) so without this change every message (if it's the only buffered message) cost an additional object here

* We should not create a new wrapper object if there's no bytes in the `ByteBuf`
* We should not create a new wrapped `ByteBuf` if it can't contain a message anyway because it doesn't even have enough bytes for a header left
@original-brownbear original-brownbear added >non-issue :Distributed/Network Http and internode communication implementations v8.0.0 v7.4.0 labels Jul 21, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

@@ -35,7 +35,7 @@
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
try {
boolean continueDecode = true;
boolean continueDecode = in.readableBytes() >= HEADER_SIZE;
while (continueDecode) {
int messageLength = TcpTransport.readMessageLength(Netty4Utils.toBytesReference(in));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the cost of some duplication (between Netty and NIO impls.) we could just remove creating the wrapping BytesReference just for reading the length here as well. I'd look into that in a follow up.

@original-brownbear
Copy link
Member Author

@ywelsch fixed :)

Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@original-brownbear
Copy link
Member Author

thanks @ywelsch !

@original-brownbear original-brownbear merged commit d3b9b04 into elastic:master Jul 30, 2019
@original-brownbear original-brownbear deleted the faster-size-frame-decoder branch July 30, 2019 11:14
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request Jul 30, 2019
* We should not create a new wrapper object if there's no bytes in the `ByteBuf`
* We should not create a new wrapped `ByteBuf` if it can't contain a message anyway because it doesn't even have enough bytes for a header left
original-brownbear added a commit that referenced this pull request Jul 30, 2019
* We should not create a new wrapper object if there's no bytes in the `ByteBuf`
* We should not create a new wrapped `ByteBuf` if it can't contain a message anyway because it doesn't even have enough bytes for a header left
jkakavas pushed a commit that referenced this pull request Jul 31, 2019
* We should not create a new wrapper object if there's no bytes in the `ByteBuf`
* We should not create a new wrapped `ByteBuf` if it can't contain a message anyway because it doesn't even have enough bytes for a header left
@original-brownbear original-brownbear restored the faster-size-frame-decoder branch August 6, 2020 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed/Network Http and internode communication implementations >non-issue v7.4.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants