Skip to content

provides set of fixes and test for tuple byte buffs - #739

Closed
OlegDokuka wants to merge 1 commit into
developfrom
bugfix/tuple-bb
Closed

OlegDokuka wants to merge 1 commit into
developfrom
bugfix/tuple-bb

Conversation

@OlegDokuka

@OlegDokuka OlegDokuka commented Feb 2, 2020 •

Copy link
Copy Markdown
Member

This PR provides tests and a couple of bugfixes for TupleByteBuf

  1. Adopted default ByteBuf test suit for TupleByteBuf

  2. Removes custom toString implementation in favor of built-in one https://github.com/rsocket/rsocket-java/pull/739/files#diff-639e901074347653a889b0c9c393f25dL364

  3. Fixes readXXX for LittleEndian (https://github.com/rsocket/rsocket-java/pull/739/files#diff-183345d04c26e98d76cdd661694c7e8dL200)

  4. Proper endiance switch support (https://github.com/rsocket/rsocket-java/pull/739/files#diff-183345d04c26e98d76cdd661694c7e8dR217) by default it should be BigEndian. On the other hand, I removed override method https://github.com/rsocket/rsocket-java/pull/739/files#diff-183345d04c26e98d76cdd661694c7e8dL232 which causes illegal behavior when netty tries to switch byte ordering in some cases

  5. Fixes behaviors of unwrap method

  6. Fixes behavior for setIndex(int, int) writerIndex(int) method (should change index for TupleByteBuf but should not let write data

  7. Removes custom implementation of slice() method since it created incorrect slice which violates the base test suit

Signed-off-by: Oleh Dokuka shadowgun@i.ua

Signed-off-by: Oleh Dokuka <shadowgun@i.ua>

@Override
public ByteBuf unwrap() {
throw new UnsupportedOperationException();

@yschimke yschimke Feb 2, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

mistake?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Looks like. Please see https://netty.io/4.0/api/io/netty/buffer/ByteBuf.html#unwrap--

Return the underlying buffer instance if this buffer is a wrapper of another buffer.
Returns:
null if this buffer is not a wrapper

import java.nio.channels.FileChannel;
import java.nio.channels.ScatteringByteChannel;

abstract class AbstractReadOnlyReferenceCountedByteBuf extends AbstractReferenceCountedByteBuf {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The netty docs deprecated similar classes and suggest using Unpooled.wrappedUnmodifiableBuffer. Also the docs call out slice as an issue, how is this handled?

https://netty.io/4.1/api/io/netty/buffer/Unpooled.html#wrappedUnmodifiableBuffer-io.netty.buffer.ByteBuf...-

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It is deprecated but there are no other options to extend. TupledByteBuf designed to be readOnly and I don't wanna create few more objects to runtime just in order to use what netty gives. therefore I mimic the same what readonly bytebuf does

@yschimke

yschimke commented Feb 2, 2020

Copy link
Copy Markdown
Member

Can you call out the fixes specifically?

@OlegDokuka

OlegDokuka commented Feb 3, 2020 •

Copy link
Copy Markdown
Member Author

Can you call out the fixes specifically?

I added more explanation on the fixes I have done.

In general, PR adopts netty bytebuf test-suite which ensures proper implementation of rsocket bytebuf. On the other hand, most of the fixes were discovered as the result of running adopted test-suit against the implementation

/cc @yschimke @simonbasle

@mostroverkhov mostroverkhov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TupleByteBuf was originally intended to reduce copying, but unfortunately with SSL handler on pipeline It can make performance worse: engine cant append Bytebufs (until fit single TLS record) because Tuple is not writable, so allocates new buffer and does copy anyways. Do you think It makes sense to optimise for plaintext over TLS?
Also AFAIK buggy TupleByteBuf implementation was one of the reasons (together with #709) any release after 0.12.2-RC4 (transitively current spring-boot and spring-integration) is unstable & unusable with TLS enabled transports. SSLHandler is the only one example - custom implementation of huge ByteBuf interface may easily have more bugs revealed with other netty handlers.
I suggest giving users choice between pragmatic and stable CompositeByteBuf and custom one, move TupleByteBuf out of core to project - there were enough issues with It.

@OlegDokuka

OlegDokuka commented Feb 6, 2020 •

Copy link
Copy Markdown
Member Author

TupleByteBuf was originally intended to reduce copying, but unfortunately with SSL handler on pipeline It can make performance worse: engine cant append Bytebufs (until fit single TLS record) because Tuple is not writable, so allocates new buffer and does copy anyways. Do you think It makes sense to optimise for plaintext over TLS?
Also AFAIK buggy TupleByteBuf implementation was one of the reasons (together with #709) any release after 0.12.2-RC4 (transitively current spring-boot and spring-integration) is unstable & unusable with TLS enabled transports. SSLHandler is the only one example - custom implementation of huge ByteBuf interface may easily have more bugs revealed with other netty handlers.
I suggest giving users choice between pragmatic and stable CompositeByteBuf and a custom one, move TupleByteBuf out of core to project - there were enough issues with It.

I'm not sure this comment might ever be applicable to this PR since it's main intent is to provide a test suite for tupplebytebuf rather than to doubt its need.
If you would like to rise that problem and run a discussion over, it is better to discuss that in a separate issue. In general, more than appreciate benchmarks that confirm insignificant performance impact.

In general, I was thinking of making TupleByteBuf writable, counting the fact that right now we have issues with TLS

@mostroverkhov
mostroverkhov requested review from mostroverkhov and removed request for mostroverkhov February 6, 2020 21:31
@mostroverkhov

Copy link
Copy Markdown
Member

This is follow up on Yurii request reqarding justification for 5k LOC bugfix.

 I was thinking of making TupleByteBuf writable

please do, but with an option for people to select implementation (CompositeByteBuf is pragmatic and stable one), and move TupleByteBuf to project which you think will benefit from It 😄

@yschimke

yschimke commented Feb 7, 2020

Copy link
Copy Markdown
Member

FWIW I'm providing advisory drive-by reviews, not much code recently. There is a cautious balance between the need to write optimised code to avoid every allocation and keeping the code simple.

I'm naturally inclined towards reuse of existing code from netty and reactor. So take my queries as mainly trying to keep that tension.

@OlegDokuka

OlegDokuka commented Feb 7, 2020 •

Copy link
Copy Markdown
Member Author

As I said before, mainly, the justification for this PR is to provide a test-suit and subsequently bugfix incorrect behavior.

Justification for TupleByteBuf in general is to improve performance, which, for instance, gives around 100k RPS for simple request-response communication (that is about 10-15% from the baseline - CompositeByteBuf).

@OlegDokuka

Copy link
Copy Markdown
Member Author

Needs rethinking

@OlegDokuka OlegDokuka closed this Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants