diff --git a/debezium-microbenchmark/pom.xml b/debezium-microbenchmark/pom.xml new file mode 100644 index 000000000..9aa6332ce --- /dev/null +++ b/debezium-microbenchmark/pom.xml @@ -0,0 +1,101 @@ + + + + io.debezium + debezium-parent + 0.8.0-SNAPSHOT + ../pom.xml + + 4.0.0 + debezium-microbenchmark + Debezium Microbenchmark Tests + jar + + + io.debezium + debezium-core + + + io.debezium + debezium-connector-mysql + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + log4j + log4j + + + org.openjdk.jmh + jmh-core + + + org.openjdk.jmh + jmh-generator-annprocess + + + + + + + true + src/main/resources + + **/build.properties + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + **/generated/** + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + ${project.artifactId} + + + MANIFEST.MF + + + org.openjdk.jmh.Main + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + + diff --git a/debezium-microbenchmark/src/main/java/io/debezium/performance/connector/mysql/parser/MySqlDdlParserPerf.java b/debezium-microbenchmark/src/main/java/io/debezium/performance/connector/mysql/parser/MySqlDdlParserPerf.java new file mode 100644 index 000000000..705a42e70 --- /dev/null +++ b/debezium-microbenchmark/src/main/java/io/debezium/performance/connector/mysql/parser/MySqlDdlParserPerf.java @@ -0,0 +1,87 @@ +/* + * Copyright Debezium Authors. + * + * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package io.debezium.performance.connector.mysql.parser; + +import java.util.concurrent.TimeUnit; + +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.Warmup; + +import io.debezium.connector.mysql.MySqlDdlParser; +import io.debezium.connector.mysql.antlr.MySqlAntlrDdlParser; +import io.debezium.relational.Tables; +import io.debezium.relational.ddl.AbstractDdlParser; + +/** + * A basic test to compare performance of legacy and antlr DDL parsers depending on the amount + * of columns in the statement. + * + * @author Jiri Pechanec + * + */ +public class MySqlDdlParserPerf { + + @State(Scope.Thread) + public static class ParserState { + + public AbstractDdlParser legacyParser; + public AbstractDdlParser antlrParser; + public Tables tables; + public String ddl; + + @Param({"1", "2", "5", "10", "20", "50"}) + public int columnCount; + + + @Setup(Level.Trial) + public void doSetup() { + legacyParser = new MySqlDdlParser(); + antlrParser = new MySqlAntlrDdlParser(); + tables = new Tables(); + ddl = testStatement(); + } + + private String testStatement() { + final StringBuilder sb = new StringBuilder("CREATE TABLE t1 (id int primary key"); + for (int i = 0; i < columnCount; i++) { + sb.append(", v").append(i).append(" int"); + } + final String statement = sb.append(")").toString(); + return statement; + } + } + + + @Benchmark + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.MICROSECONDS) + @Fork(value = 1) + @Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS) + @Measurement(iterations = 3, time = 2, timeUnit = TimeUnit.SECONDS) + public void legacy(ParserState state) { + state.legacyParser.parse(state.ddl, state.tables); + } + + @Benchmark + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.MICROSECONDS) + @Fork(value = 1) + @Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS) + @Measurement(iterations = 3, time = 2, timeUnit = TimeUnit.SECONDS) + public void antlr(ParserState state) { + state.antlrParser.parse(state.ddl, state.tables); + } +} diff --git a/pom.xml b/pom.xml index b661e574d..f279be73f 100644 --- a/pom.xml +++ b/pom.xml @@ -82,8 +82,9 @@ 4.12 1.4 + 1.21 - + 2.7 2.10 3.0.0-M1 @@ -121,6 +122,7 @@ debezium-connector-mysql debezium-connector-postgres debezium-connector-mongodb + debezium-microbenchmark @@ -298,6 +300,16 @@ fest-assert ${version.fest} + + org.openjdk.jmh + jmh-core + ${version.jmh} + + + org.openjdk.jmh + jmh-generator-annprocess + ${version.jmh} +