generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 181
Add micro benchmarks for unified query layer #5043
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
dai-chen
merged 5 commits into
opensearch-project:main
from
dai-chen:add-microbenchmark-for-unified-query-api
Jan 21, 2026
+241
−1
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0762a1a
Add microbenchmark for unified query APIs
dai-chen 8e50ba5
Add benchmark for unified function
dai-chen 01c062b
Refactor javadoc and helper method
dai-chen 7938fbe
Fix spotless check failure
dai-chen 3b0315b
Address CodeRabit comment
dai-chen 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
File renamed without changes.
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
128 changes: 128 additions & 0 deletions
128
benchmarks/src/jmh/java/org/opensearch/sql/api/UnifiedFunctionBenchmark.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,128 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.api; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.openjdk.jmh.annotations.BenchmarkMode; | ||
| import org.openjdk.jmh.annotations.Fork; | ||
| import org.openjdk.jmh.annotations.Level; | ||
| import org.openjdk.jmh.annotations.Measurement; | ||
| import org.openjdk.jmh.annotations.Mode; | ||
| import org.openjdk.jmh.annotations.OperationsPerInvocation; | ||
| import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
| import org.openjdk.jmh.annotations.Param; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.Setup; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import org.openjdk.jmh.annotations.TearDown; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
| import org.openjdk.jmh.infra.Blackhole; | ||
| import org.opensearch.sql.api.function.UnifiedFunction; | ||
| import org.opensearch.sql.api.function.UnifiedFunctionRepository; | ||
|
|
||
| /** | ||
| * JMH benchmark for measuring {@link UnifiedFunction} performance. Tests one representative | ||
| * function per PPL category (json, math, conditional, collection, string). | ||
| * | ||
| * <p>Benchmarks: | ||
| * | ||
| * <ul> | ||
| * <li>{@link #loadFunction()}: Measures function loading from repository | ||
| * <li>{@link #evalFunction(Blackhole)}: Measures function evaluation (1000 calls per invocation) | ||
| * </ul> | ||
| */ | ||
| @Warmup(iterations = 2, time = 1) | ||
| @Measurement(iterations = 5, time = 1) | ||
| @BenchmarkMode(Mode.AverageTime) | ||
| @OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
| @State(Scope.Thread) | ||
| @Fork(value = 1) | ||
| public class UnifiedFunctionBenchmark extends UnifiedQueryTestBase { | ||
|
|
||
| /** Number of function evaluations per benchmark invocation. */ | ||
| private static final int OPS = 1000; | ||
|
|
||
| /** Benchmark specification selecting which function to test. */ | ||
| @Param public BenchmarkSpec benchmarkSpec; | ||
|
|
||
| /** Repository for loading unified functions. */ | ||
| private UnifiedFunctionRepository repository; | ||
|
|
||
| /** Pre-loaded function instance for evaluation benchmarks. */ | ||
| private UnifiedFunction function; | ||
|
|
||
| /** Input arguments for function evaluation. */ | ||
| private List<Object> inputs; | ||
|
|
||
| @Setup(Level.Trial) | ||
| public void setUpBenchmark() { | ||
| super.setUp(); | ||
|
|
||
| repository = new UnifiedFunctionRepository(context); | ||
| function = benchmarkSpec.loadFunction(repository); | ||
| inputs = benchmarkSpec.getInputs(); | ||
| } | ||
|
|
||
| @TearDown(Level.Trial) | ||
| public void tearDownBenchmark() throws Exception { | ||
| super.tearDown(); | ||
| } | ||
|
|
||
| /** Benchmarks function loading from repository. */ | ||
| @Benchmark | ||
| public UnifiedFunction loadFunction() { | ||
| return benchmarkSpec.loadFunction(repository); | ||
| } | ||
|
|
||
| /** Benchmarks function evaluation with pre-loaded function and inputs. */ | ||
| @Benchmark | ||
| @OperationsPerInvocation(OPS) | ||
| public void evalFunction(Blackhole bh) { | ||
| for (int i = 0; i < OPS; i++) { | ||
| bh.consume(function.eval(inputs)); | ||
| } | ||
| } | ||
|
|
||
| /** Enum defining benchmark test cases - one representative function per PPL category. */ | ||
| @RequiredArgsConstructor | ||
| public enum BenchmarkSpec { | ||
| JSON_EXTRACT( | ||
| inputTypes("VARCHAR", "VARCHAR"), | ||
| sampleInputs("{\"name\":\"test\",\"value\":42}", "$.name")), | ||
| COALESCE( | ||
| inputTypes("VARCHAR", "VARCHAR", "VARCHAR"), | ||
| sampleInputs(null, "first_value", "default_value")), | ||
| MVFIND( | ||
| inputTypes("ARRAY", "VARCHAR"), | ||
| sampleInputs(List.of("debug", "error", "warn", "info"), "err.*")), | ||
| REX_EXTRACT( | ||
| inputTypes("VARCHAR", "VARCHAR", "INTEGER"), | ||
| sampleInputs("192.168.1.1 - GET /api", "(\\d+)", 1)); | ||
|
|
||
| private final List<String> inputTypes; | ||
| @Getter private final List<Object> inputs; | ||
|
|
||
| UnifiedFunction loadFunction(UnifiedFunctionRepository repository) { | ||
| return repository | ||
| .loadFunction(name()) | ||
| .map(desc -> desc.getBuilder().build(inputTypes)) | ||
| .orElseThrow(); | ||
| } | ||
|
|
||
| private static List<String> inputTypes(String... types) { | ||
| return List.of(types); | ||
| } | ||
|
|
||
| private static List<Object> sampleInputs(Object... args) { | ||
| return Arrays.asList(args); | ||
| } | ||
| } | ||
| } | ||
87 changes: 87 additions & 0 deletions
87
benchmarks/src/jmh/java/org/opensearch/sql/api/UnifiedQueryBenchmark.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,87 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.api; | ||
|
|
||
| import java.sql.PreparedStatement; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.apache.calcite.rel.RelNode; | ||
| import org.apache.calcite.sql.dialect.SparkSqlDialect; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.openjdk.jmh.annotations.BenchmarkMode; | ||
| import org.openjdk.jmh.annotations.Fork; | ||
| import org.openjdk.jmh.annotations.Level; | ||
| import org.openjdk.jmh.annotations.Measurement; | ||
| import org.openjdk.jmh.annotations.Mode; | ||
| import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
| import org.openjdk.jmh.annotations.Param; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.Setup; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import org.openjdk.jmh.annotations.TearDown; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
| import org.opensearch.sql.api.compiler.UnifiedQueryCompiler; | ||
| import org.opensearch.sql.api.transpiler.UnifiedQueryTranspiler; | ||
|
|
||
| /** | ||
| * JMH benchmark for measuring the overhead of unified query API components when processing queries. | ||
| * This provides baseline metrics and guidance for API consumers during integration. | ||
| */ | ||
| @Warmup(iterations = 2, time = 1) | ||
| @Measurement(iterations = 5, time = 1) | ||
| @BenchmarkMode(Mode.AverageTime) | ||
| @OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
| @State(Scope.Thread) | ||
| @Fork(value = 1) | ||
| public class UnifiedQueryBenchmark extends UnifiedQueryTestBase { | ||
|
|
||
| /** Common query patterns for benchmarking. */ | ||
| @Param({ | ||
| "source = catalog.employees", | ||
| "source = catalog.employees | where age > 30", | ||
| "source = catalog.employees | stats count() by department", | ||
| "source = catalog.employees | sort - age", | ||
| "source = catalog.employees | where age > 25 | stats avg(age) by department | sort - department" | ||
| }) | ||
| private String query; | ||
|
|
||
| /** Transpiler for converting logical plans to SQL strings. */ | ||
| private UnifiedQueryTranspiler transpiler; | ||
|
|
||
| /** Compiler for converting logical plans to executable statements. */ | ||
| private UnifiedQueryCompiler compiler; | ||
|
|
||
| @Setup(Level.Trial) | ||
| public void setUpBenchmark() { | ||
| super.setUp(); | ||
| transpiler = UnifiedQueryTranspiler.builder().dialect(SparkSqlDialect.DEFAULT).build(); | ||
| compiler = new UnifiedQueryCompiler(context); | ||
| } | ||
|
|
||
| @TearDown(Level.Trial) | ||
| public void tearDownBenchmark() throws Exception { | ||
| super.tearDown(); | ||
| } | ||
|
|
||
| /** Benchmarks query parsing and Calcite logical plan generation. */ | ||
| @Benchmark | ||
| public RelNode planQuery() { | ||
| return planner.plan(query); | ||
| } | ||
|
|
||
| /** Benchmarks the full transpilation pipeline: Query → logical plan → SQL string. */ | ||
| @Benchmark | ||
| public String transpileToSql() { | ||
| RelNode plan = planner.plan(query); | ||
| return transpiler.toSql(plan); | ||
| } | ||
|
|
||
| /** Benchmarks the compilation pipeline: Query → logical plan → executable statement. */ | ||
| @Benchmark | ||
| public PreparedStatement compileQuery() { | ||
| RelNode plan = planner.plan(query); | ||
| return compiler.compile(plan); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.