From d47d6cf081d386a1523e2d16904962eab987eb82 Mon Sep 17 00:00:00 2001 From: Jihoon Son Date: Tue, 1 Dec 2020 10:32:37 -0800 Subject: [PATCH] Add time-to-first-result benchmark for groupBy (#10612) --- .../benchmark/query/GroupByBenchmark.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/benchmarks/src/test/java/org/apache/druid/benchmark/query/GroupByBenchmark.java b/benchmarks/src/test/java/org/apache/druid/benchmark/query/GroupByBenchmark.java index f212fe38529..1e93d166698 100644 --- a/benchmarks/src/test/java/org/apache/druid/benchmark/query/GroupByBenchmark.java +++ b/benchmarks/src/test/java/org/apache/druid/benchmark/query/GroupByBenchmark.java @@ -38,6 +38,8 @@ import org.apache.druid.java.util.common.concurrent.Execs; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.granularity.Granularity; import org.apache.druid.java.util.common.guava.Sequence; +import org.apache.druid.java.util.common.guava.Yielder; +import org.apache.druid.java.util.common.guava.Yielders; import org.apache.druid.java.util.common.logger.Logger; import org.apache.druid.math.expr.ExprMacroTable; import org.apache.druid.offheap.OffheapBufferGenerator; @@ -682,6 +684,28 @@ public class GroupByBenchmark blackhole.consume(results); } + /** + * Measure the time to produce the first ResultRow unlike {@link #queryMultiQueryableIndexX} measures total query + * processing time. This measure is useful since the Broker can start merging as soon as the first result is returned. + */ + @Benchmark + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.MICROSECONDS) + public void queryMultiQueryableIndexTTFR(Blackhole blackhole) throws IOException + { + QueryToolChest toolChest = factory.getToolchest(); + QueryRunner theRunner = new FinalizeResultsQueryRunner<>( + toolChest.mergeResults( + factory.mergeRunners(executorService, makeMultiRunners()) + ), + (QueryToolChest) toolChest + ); + + Sequence queryResult = theRunner.run(QueryPlus.wrap(query), ResponseContext.createEmpty()); + Yielder yielder = Yielders.each(queryResult); + yielder.close(); + } + @Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS) @@ -703,6 +727,32 @@ public class GroupByBenchmark blackhole.consume(results); } + /** + * Measure the time to produce the first ResultRow unlike {@link #queryMultiQueryableIndexWithSpilling} measures + * total query processing time. This measure is useful since the Broker can start merging as soon as the first + * result is returned. + */ + @Benchmark + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.MICROSECONDS) + public void queryMultiQueryableIndexWithSpillingTTFR(Blackhole blackhole) throws IOException + { + QueryToolChest toolChest = factory.getToolchest(); + QueryRunner theRunner = new FinalizeResultsQueryRunner<>( + toolChest.mergeResults( + factory.mergeRunners(executorService, makeMultiRunners()) + ), + (QueryToolChest) toolChest + ); + + final GroupByQuery spillingQuery = query.withOverriddenContext( + ImmutableMap.of("bufferGrouperMaxSize", 4000) + ); + Sequence queryResult = theRunner.run(QueryPlus.wrap(spillingQuery), ResponseContext.createEmpty()); + Yielder yielder = Yielders.each(queryResult); + yielder.close(); + } + @Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS)