Skip to content

Commit

Permalink
fixes performance degradation when fragmentation is used (#995)
Browse files Browse the repository at this point in the history
  • Loading branch information
koldat authored Mar 4, 2021
1 parent 765abb7 commit e4d62b6
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,18 @@ public static int assertMtu(int mtu) {

@Override
public Mono<Void> send(Publisher<ByteBuf> frames) {
return Flux.from(frames).concatMap(this::sendOne).then();
return delegate.send(
Flux.from(frames)
.concatMap(
frame -> {
FrameType frameType = FrameHeaderCodec.frameType(frame);
int readableBytes = frame.readableBytes();
if (!shouldFragment(frameType, readableBytes)) {
return Flux.just(frame);
}

return logFragments(Flux.from(fragmentFrame(alloc(), mtu, frame, frameType)));
}));
}

@Override
Expand All @@ -95,6 +106,11 @@ public Mono<Void> sendOne(ByteBuf frame) {
return delegate.sendOne(frame);
}
Flux<ByteBuf> fragments = Flux.from(fragmentFrame(alloc(), mtu, frame, frameType));
fragments = logFragments(fragments);
return delegate.send(fragments);
}

protected Flux<ByteBuf> logFragments(Flux<ByteBuf> fragments) {
if (logger.isDebugEnabled()) {
fragments =
fragments.doOnNext(
Expand All @@ -107,6 +123,6 @@ public Mono<Void> sendOne(ByteBuf frame) {
ByteBufUtil.prettyHexDump(byteBuf));
});
}
return delegate.send(fragments);
return fragments;
}
}

0 comments on commit e4d62b6

Please sign in to comment.