-
Notifications
You must be signed in to change notification settings - Fork 356
Fragmentation #481
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
Merged
Merged
Fragmentation #481
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 0 additions & 112 deletions
112
rsocket-core/src/jmh/java/io/rsocket/FragmentationPerf.java
This file was deleted.
Oops, something went wrong.
152 changes: 152 additions & 0 deletions
152
rsocket-core/src/jmh/java/io/rsocket/fragmentation/FragmentationPerformanceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* | ||
* Copyright 2015-2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.rsocket.fragmentation; | ||
|
||
import static io.netty.buffer.UnpooledByteBufAllocator.DEFAULT; | ||
import static io.rsocket.framing.RequestResponseFrame.createRequestResponseFrame; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.ByteBufAllocator; | ||
import io.netty.buffer.Unpooled; | ||
import io.rsocket.framing.Frame; | ||
import java.util.List; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
import reactor.core.publisher.SynchronousSink; | ||
import reactor.util.context.Context; | ||
|
||
@BenchmarkMode(Mode.Throughput) | ||
@Fork( | ||
value = 1 // , jvmArgsAppend = {"-Dio.netty.leakDetection.level=advanced"} | ||
) | ||
@Warmup(iterations = 10) | ||
@Measurement(iterations = 10_000) | ||
@State(Scope.Thread) | ||
public class FragmentationPerformanceTest { | ||
|
||
@Benchmark | ||
public void largeFragmentation(Input input) { | ||
Frame frame = | ||
input.largeFragmenter.fragment(input.largeFrame).doOnNext(Frame::dispose).blockLast(); | ||
|
||
input.bh.consume(frame); | ||
} | ||
|
||
@Benchmark | ||
public void largeReassembly(Input input) { | ||
input.largeFrames.forEach(frame -> input.reassembler.reassemble(frame, input.sink)); | ||
|
||
input.bh.consume(input.sink.next); | ||
} | ||
|
||
@Benchmark | ||
public void smallFragmentation(Input input) { | ||
Frame frame = | ||
input.smallFragmenter.fragment(input.smallFrame).doOnNext(Frame::dispose).blockLast(); | ||
|
||
input.bh.consume(frame); | ||
} | ||
|
||
@Benchmark | ||
public void smallReassembly(Input input) { | ||
input.smallFrames.forEach(frame -> input.reassembler.reassemble(frame, input.sink)); | ||
|
||
input.bh.consume(input.sink.next); | ||
} | ||
|
||
@State(Scope.Benchmark) | ||
public static class Input { | ||
|
||
Blackhole bh; | ||
|
||
FrameFragmenter largeFragmenter; | ||
|
||
Frame largeFrame; | ||
|
||
List<Frame> largeFrames; | ||
|
||
FrameReassembler reassembler = FrameReassembler.createFrameReassembler(DEFAULT); | ||
|
||
MockSynchronousSink<Frame> sink; | ||
|
||
FrameFragmenter smallFragmenter; | ||
|
||
Frame smallFrame; | ||
|
||
List<Frame> smallFrames; | ||
|
||
@Setup | ||
public void setup(Blackhole bh) { | ||
this.bh = bh; | ||
|
||
sink = new MockSynchronousSink<>(); | ||
|
||
largeFrame = | ||
createRequestResponseFrame( | ||
DEFAULT, false, getRandomByteBuf(1 << 18), getRandomByteBuf(1 << 18)); | ||
|
||
smallFrame = | ||
createRequestResponseFrame(DEFAULT, false, getRandomByteBuf(16), getRandomByteBuf(16)); | ||
|
||
largeFragmenter = new FrameFragmenter(DEFAULT, 1024); | ||
smallFragmenter = new FrameFragmenter(ByteBufAllocator.DEFAULT, 2); | ||
|
||
largeFrames = largeFragmenter.fragment(largeFrame).collectList().block(); | ||
smallFrames = smallFragmenter.fragment(smallFrame).collectList().block(); | ||
} | ||
|
||
private static ByteBuf getRandomByteBuf(int size) { | ||
byte[] bytes = new byte[size]; | ||
ThreadLocalRandom.current().nextBytes(bytes); | ||
return Unpooled.wrappedBuffer(bytes); | ||
} | ||
} | ||
|
||
static final class MockSynchronousSink<T> implements SynchronousSink<T> { | ||
|
||
Throwable error; | ||
|
||
T next; | ||
|
||
@Override | ||
public void complete() {} | ||
|
||
@Override | ||
public Context currentContext() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void error(Throwable e) { | ||
this.error = e; | ||
} | ||
|
||
@Override | ||
public void next(T t) { | ||
this.next = t; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to include a log implementation in the dependencies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the
dependencyManagment
plugin declaration. Adding it here creates a logical dependency with a version number, but doesn't actually attach it to any artifact. It makes it possible to add it as atestRuntimeOnly
dependency to multiple projects without having to keep the version number in sync across all of them.