Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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[]{

Copy link
Copy Markdown
Contributor

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.

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)
Expand All @@ -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)
Expand All @@ -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();
Expand All @@ -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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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;
}
}
}
Comment thread
prudhvimaharishi marked this conversation as resolved.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
@State(Scope.Benchmark)
public class GcsReadChannelBenchmarkState {

@Param({"SEQUENTIAL", "RANDOM"})
@Param({"SEQUENTIAL", "RANDOM", "AUTO_SEQUENTIAL", "AUTO_RANDOM"})
public FileAccessPattern accessPattern;
}
Loading