-
Notifications
You must be signed in to change notification settings - Fork 17
feat: Add jmh benchmarks for adaptive range reads. #277
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
Open
prudhvimaharishi
wants to merge
1
commit into
GoogleCloudPlatform:feature/adaptive-range-read
Choose a base branch
from
prudhvimaharishi:adaptive-6
base: feature/adaptive-range-read
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,11 +40,12 @@ | |
| public class GcsReadChannelBenchmark { | ||
|
|
||
| private GcsItemId itemId; | ||
| private byte[] buffer; | ||
| private byte[] largeBuffer; | ||
|
|
||
| private GoogleCloudStorageInputStream stream; | ||
| private GcsFileSystem gcsFileSystem; | ||
| private GcsReadOptions options; | ||
| private ByteBuffer localBuffer; | ||
| private long[] offsets; | ||
|
|
||
| @Setup(Level.Trial) | ||
| public void setup(GcsReadChannelBenchmarkState state) throws IOException { | ||
|
|
@@ -53,8 +54,20 @@ public void setup(GcsReadChannelBenchmarkState state) throws IOException { | |
| .setBucketName(IntegrationTestHelper.BUCKET_NAME) | ||
| .setObjectName(IntegrationTestHelper.getFolderName() + IntegrationTestHelper.TPCDS_CUSTOMER_MEDIUM_FILE) | ||
| .build(); | ||
| buffer = new byte[1024]; | ||
| largeBuffer = new byte[100 * 1024]; | ||
|
|
||
| localBuffer = ByteBuffer.allocate(64 * 1024); | ||
| offsets = new long[]{ | ||
| 1024, | ||
| 1024 * 1024, | ||
| 512 * 1024, | ||
| 2 * 1024 * 1024, | ||
| 128 * 1024, | ||
| 3 * 1024 * 1024, | ||
| 256 * 1024, | ||
| 4 * 1024 * 1024, | ||
| 32 * 1024, | ||
| 4 * 1024 * 1024 + 512 * 1024 | ||
| }; | ||
|
|
||
| options = GcsReadOptions.builder() | ||
| .setFileAccessPattern(state.accessPattern) | ||
|
|
@@ -79,41 +92,6 @@ public void tearDownInvocation() throws IOException { | |
| } | ||
| } | ||
|
|
||
| private void readWithSeek(int seekDistance) throws IOException { | ||
| stream.read(buffer); | ||
| stream.seek(seekDistance); | ||
| stream.read(buffer); | ||
| } | ||
|
|
||
| @Benchmark | ||
| @BenchmarkMode(Mode.AverageTime) | ||
| @OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
| @Warmup(iterations = 5, time = 1) | ||
| @Measurement(iterations = 10, time = 1) | ||
| @Fork(value = 2, warmups = 0) | ||
| public void readWith128KSeek(GcsReadChannelBenchmarkState state) throws IOException { | ||
| readWithSeek(128 * 1024); | ||
| } | ||
|
|
||
| @Benchmark | ||
| @BenchmarkMode(Mode.AverageTime) | ||
| @OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
| @Warmup(iterations = 5, time = 1) | ||
| @Measurement(iterations = 10, time = 1) | ||
| @Fork(value = 2, warmups = 0) | ||
| public void readWith512KSeek(GcsReadChannelBenchmarkState state) throws IOException { | ||
| readWithSeek(512 * 1024); | ||
| } | ||
|
|
||
| @Benchmark | ||
| @BenchmarkMode(Mode.AverageTime) | ||
| @OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
| @Warmup(iterations = 5, time = 1) | ||
| @Measurement(iterations = 10, time = 1) | ||
| @Fork(value = 2, warmups = 0) | ||
| public void readWith1MSeek(GcsReadChannelBenchmarkState state) throws IOException { | ||
| readWithSeek(1024 * 1024); | ||
| } | ||
|
|
||
| @Benchmark | ||
| @BenchmarkMode(Mode.AverageTime) | ||
|
|
@@ -122,8 +100,7 @@ public void readWith1MSeek(GcsReadChannelBenchmarkState state) throws IOExceptio | |
| @Measurement(iterations = 10, time = 1) | ||
| @Fork(value = 2, warmups = 0) | ||
| public void sequentialRead(GcsReadChannelBenchmarkState state) throws IOException { | ||
| ByteBuffer localBuffer = ByteBuffer.allocate(64 * 1024); | ||
| int bytesToRead = 2 * 1024 * 1024; | ||
| int bytesToRead = 8 * 1024 * 1024; | ||
| int bytesRead = 0; | ||
| while (bytesRead < bytesToRead) { | ||
| localBuffer.clear(); | ||
|
|
@@ -139,25 +116,15 @@ public void sequentialRead(GcsReadChannelBenchmarkState state) throws IOExceptio | |
| @Warmup(iterations = 5, time = 1) | ||
| @Measurement(iterations = 10, time = 1) | ||
| @Fork(value = 2, warmups = 0) | ||
| public void readWithBackwardSeek(GcsReadChannelBenchmarkState state) throws IOException { | ||
| stream.read(buffer); | ||
| stream.seek(512 * 1024); | ||
| stream.read(buffer); | ||
| stream.seek(256 * 1024); | ||
| stream.read(buffer); | ||
| } | ||
|
|
||
| @Benchmark | ||
| @BenchmarkMode(Mode.AverageTime) | ||
| @OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
| @Warmup(iterations = 5, time = 1) | ||
| @Measurement(iterations = 10, time = 1) | ||
| @Fork(value = 2, warmups = 0) | ||
| public void readWithBackwardSeekLargeRead(GcsReadChannelBenchmarkState state) throws IOException { | ||
| stream.read(buffer); | ||
| stream.seek(512 * 1024); | ||
| stream.read(buffer); | ||
| stream.seek(256 * 1024); | ||
| stream.read(largeBuffer); | ||
| public void randomRead(GcsReadChannelBenchmarkState state) throws IOException { | ||
| for (long offset : offsets) { | ||
| localBuffer.clear(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. define localBuffer here itself, what is size of the localBuffer is interesting detail and is hidden here and one needs to search outside the spec. |
||
| stream.seek(offset); | ||
| while (localBuffer.hasRemaining()) { | ||
| if (stream.read(localBuffer) == -1) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
prudhvimaharishi marked this conversation as resolved.
|
||
| } | ||
| } | ||
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.
This could be a static constant, rename it to be more meaningful. Eg: <READ_PATTERN>_OFFSETS.