diff --git a/core/src/jmh/java/com/google/cloud/gcs/analyticscore/client/GcsReadChannelBenchmark.java b/core/src/jmh/java/com/google/cloud/gcs/analyticscore/client/GcsReadChannelBenchmark.java index f8f07ab4..5709b0c7 100644 --- a/core/src/jmh/java/com/google/cloud/gcs/analyticscore/client/GcsReadChannelBenchmark.java +++ b/core/src/jmh/java/com/google/cloud/gcs/analyticscore/client/GcsReadChannelBenchmark.java @@ -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(); + stream.seek(offset); + while (localBuffer.hasRemaining()) { + if (stream.read(localBuffer) == -1) { + break; + } + } + } } } diff --git a/core/src/jmh/java/com/google/cloud/gcs/analyticscore/client/GcsReadChannelBenchmarkState.java b/core/src/jmh/java/com/google/cloud/gcs/analyticscore/client/GcsReadChannelBenchmarkState.java index 0001a3af..f1433ce7 100644 --- a/core/src/jmh/java/com/google/cloud/gcs/analyticscore/client/GcsReadChannelBenchmarkState.java +++ b/core/src/jmh/java/com/google/cloud/gcs/analyticscore/client/GcsReadChannelBenchmarkState.java @@ -24,6 +24,6 @@ @State(Scope.Benchmark) public class GcsReadChannelBenchmarkState { - @Param({"SEQUENTIAL", "RANDOM"}) + @Param({"SEQUENTIAL", "RANDOM", "AUTO_SEQUENTIAL", "AUTO_RANDOM"}) public FileAccessPattern accessPattern; }