aboutsummaryrefslogtreecommitdiffstats
path: root/mdbc-benchmark/src/main
diff options
context:
space:
mode:
authorArthur Martella <arthur.martella.1@att.com>2019-03-26 18:02:52 -0400
committerTschaen, Brendan <ctschaen@att.com>2019-03-27 12:54:33 -0400
commitdd2937cafd226068dbe518d0b706dc4e6fd164ee (patch)
treec3658ce8519b1b39ba48679c4350f29974be176e /mdbc-benchmark/src/main
parenta40ee886c28bc28db1794792f1fb312b723d48fb (diff)
Improve commit log and benchmarks
Attempting to reconcile Enrique's change at https://gerrit.onap.org/r/#/c/82999/ with the current master. Change-Id: Id669c267e89d185a18d4dfa9a24852ddefcd83eb Issue-ID: MUSIC-369 Signed-off-by: Arthur Martella <arthur.martella.1@att.com>
Diffstat (limited to 'mdbc-benchmark/src/main')
-rw-r--r--mdbc-benchmark/src/main/java/org/onap/music/mdbc/BenchmarkUtils.java245
-rw-r--r--mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricBenchmark.java217
-rw-r--r--mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricCommitBenchmark.java141
-rw-r--r--mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricStatementBenchmark.java144
-rwxr-xr-xmdbc-benchmark/src/main/resources/logback.xml2
5 files changed, 553 insertions, 196 deletions
diff --git a/mdbc-benchmark/src/main/java/org/onap/music/mdbc/BenchmarkUtils.java b/mdbc-benchmark/src/main/java/org/onap/music/mdbc/BenchmarkUtils.java
new file mode 100644
index 0000000..06f2a95
--- /dev/null
+++ b/mdbc-benchmark/src/main/java/org/onap/music/mdbc/BenchmarkUtils.java
@@ -0,0 +1,245 @@
+/*
+ * ============LICENSE_START====================================================
+ * org.onap.music.mdbc
+ * =============================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END======================================================
+ */
+package org.onap.music.mdbc;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+public class BenchmarkUtils {
+ public static final String driver = "org.apache.calcite.avatica.remote.Driver";
+ public static final String mariaDriver = "org.mariadb.jdbc.Driver";
+ public static final String postgresDriver = "org.postgresql.Driver";
+ public static String TABLE;
+ public static String updateBuilder;
+
+ public enum ExecutionType {
+ MARIA_DB, COCKROACH_DB, METRIC,POSTGRES
+ }
+
+ public static void SetupTable(String table){
+ TABLE=table;
+ updateBuilder = new StringBuilder()
+ .append("UPDATE ")
+ .append(table)
+ .append(" SET Counter = Counter + 1,")
+ .append("City = 'Sandy Springs'")
+ .append(";").toString();
+ }
+
+ public static void setupCreateTables(Connection connection){
+ createTable(connection);
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ public static void setupCreateRows(Connection testConnection, int rows){
+ //Empty database
+ boolean cleanResult = BenchmarkUtils.cleanTable(testConnection);
+ //Add new lines
+ BenchmarkUtils.addRowsToTable(Integer.valueOf(rows),testConnection);
+
+ //Commit
+ try {
+ testConnection.commit();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ public static Connection getConnection(String ip, ExecutionType type, String user, String password) {
+ final String connectionUrl = "jdbc:avatica:remote:url=http://" + ip + ":30000;serialization=protobuf";
+ final String mariaConnectionUrl = "jdbc:mariadb://" + ip + ":3306/test";
+ final String cockroachUrl = "jdbc:postgresql://" + ip + ":26257/test";
+ final String postgresUrl = "jdbc:postgresql://" + ip + ":5432/test";
+
+ try {
+ switch (type) {
+ case MARIA_DB:
+ Class.forName(mariaDriver);
+ break;
+ case METRIC:
+ Class.forName(driver);
+ break;
+ case COCKROACH_DB:
+ case POSTGRES:
+ Class.forName(postgresDriver);
+ break;
+ }
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ Connection connection = null;
+ try {
+ if (type == ExecutionType.METRIC) {
+ connection = DriverManager.getConnection(connectionUrl);
+ } else {
+ Properties connectionProps = new Properties();
+ connectionProps.put("user", user);
+ if (type == ExecutionType.COCKROACH_DB) {
+ connectionProps.setProperty("sslmode", "disable");
+ } else {
+ connectionProps.put("password", password);
+ }
+ final String url = (type == ExecutionType.MARIA_DB) ? mariaConnectionUrl :
+ (type == ExecutionType.COCKROACH_DB)?cockroachUrl:postgresUrl;
+ connection = DriverManager.getConnection(url, connectionProps);
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ try {
+ connection.setAutoCommit(false);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ return connection;
+ }
+
+ public static void createTable(Connection connection) {
+ final String sql = "CREATE TABLE IF NOT EXISTS "+TABLE+" (\n" +
+ " PersonID int,\n" +
+ " Counter int,\n" +
+ " LastName varchar(255),\n" +
+ " FirstName varchar(255),\n" +
+ " Address varchar(255),\n" +
+ " City varchar(255),\n" +
+ " PRIMARY KEY(PersonID)"+
+ ");";
+
+ Statement stmt = null;
+ try {
+ stmt = connection.createStatement();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+
+ Boolean execute = null;
+ try {
+ execute = stmt.execute(sql);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+
+ try {
+ connection.commit();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+
+ try {
+ stmt.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ public static boolean cleanTable(Connection testConnection) {
+ String cleanCmd = "DELETE FROM "+TABLE+";";
+ Statement stmt = null;
+ try {
+ stmt = testConnection.createStatement();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+
+ Boolean execute = null;
+ try {
+ execute = stmt.execute(cleanCmd);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ try {
+ testConnection.commit();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ try {
+ stmt.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ return execute;
+ }
+
+ public static void addRowsToTable(int totalNumberOfRows, Connection testConnection) {
+ for (int i = 0; i < totalNumberOfRows; i++) {
+ final StringBuilder insertSQLBuilder = new StringBuilder()
+ .append("INSERT INTO "+TABLE+" VALUES (")
+ .append(i)
+ .append(", ")
+ .append(0)
+ .append(", '")
+ .append("Last-")
+ .append(i)
+ .append("', '")
+ .append("First-")
+ .append(i)
+ .append("', 'KACB', 'ATLANTA');");
+ Statement stmt = null;
+ try {
+ stmt = testConnection.createStatement();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+
+ Boolean execute = null;
+ try {
+ execute = stmt.execute(insertSQLBuilder.toString());
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ try {
+ stmt.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+ try {
+ testConnection.commit();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+
+}
diff --git a/mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricBenchmark.java b/mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricBenchmark.java
index 1fb584c..19db6f4 100644
--- a/mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricBenchmark.java
+++ b/mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricBenchmark.java
@@ -2,7 +2,7 @@
* ============LICENSE_START====================================================
* org.onap.music.mdbc
* =============================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,40 +19,39 @@
*/
package org.onap.music.mdbc;
+import static org.onap.music.mdbc.BenchmarkUtils.setupCreateRows;
+import static org.onap.music.mdbc.BenchmarkUtils.setupCreateTables;
+
+import org.onap.music.mdbc.BenchmarkUtils.ExecutionType;
import org.openjdk.jmh.annotations.*;
+import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.sql.Connection;
-import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.Properties;
import java.util.concurrent.TimeUnit;
@BenchmarkMode({Mode.AverageTime, Mode.SampleTime})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
public class MetricBenchmark {
- public StringBuilder updateBuilder = new StringBuilder()
- .append("UPDATE PERSONS ")
- .append("SET Counter = Counter + 1,")
- .append("City = 'Sandy Springs'")
- .append(";");
- public String update = updateBuilder.toString();
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(MetricBenchmark.class.getSimpleName())
.param("type", ExecutionType.METRIC.name())
+ .forks(0)
+ .threads(1)
.build();
new Runner(opt).run();
}
@Benchmark
- public boolean testMethod(MyState state) {
+ public boolean testMethod(MyState state, Blackhole blackhole) {
Statement stmt = null;
try {
stmt = state.testConnection.createStatement();
@@ -63,7 +62,7 @@ public class MetricBenchmark {
Boolean execute = null;
try {
- execute = stmt.execute(update);
+ execute = stmt.execute(state.update);
} catch (SQLException e) {
e.printStackTrace();
System.exit(1);
@@ -81,15 +80,14 @@ public class MetricBenchmark {
e.printStackTrace();
System.exit(1);
}
+ blackhole.consume(execute);
return execute;
}
- public static enum ExecutionType {
- MARIA_DB, COCKROACH_DB, METRIC
- }
@State(Scope.Benchmark)
public static class MyState {
+ public String update;
public final String driver = "org.apache.calcite.avatica.remote.Driver";
public final String mariaDriver = "org.mariadb.jdbc.Driver";
public final String cockroachDriver = "org.postgresql.Driver";
@@ -97,205 +95,34 @@ public class MetricBenchmark {
final String password = "metriccluster";
@Param({"104.209.240.219"})
public String ip;
+ @Param({"PERSONS"})
+ public String table;
@Param({"1", "10", "50", "80", "100", "200", "300", "400"})
public int rows;
- @Param({"MARIA_DB", "COCKROACH_DB", "METRIC"})
+ @Param({"MARIA_DB", "COCKROACH_DB", "METRIC", "POSTGRES"})
public ExecutionType type;
public Connection testConnection;
private Connection createConnection() {
- final String connectionUrl = "jdbc:avatica:remote:url=http://" + ip + ":30000;serialization=protobuf";
- final String mariaConnectionUrl = "jdbc:mariadb://" + ip + ":3306/test";
- final String cockroachUrl = "jdbc:postgresql://" + ip + ":26257/test";
-
- try {
- switch (type) {
- case MARIA_DB:
- Class.forName(this.mariaDriver);
- break;
- case METRIC:
- Class.forName(this.driver);
- break;
- case COCKROACH_DB:
- Class.forName(this.cockroachDriver);
- break;
- }
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- System.exit(1);
- }
- Connection connection = null;
- try {
- if (type == ExecutionType.METRIC) {
- connection = DriverManager.getConnection(connectionUrl);
- } else {
- Properties connectionProps = new Properties();
- connectionProps.put("user", user);
- if(type == ExecutionType.COCKROACH_DB){
- connectionProps.setProperty("sslmode", "disable");
- }
- else{
- connectionProps.put("password", password);
- }
- final String url = (type == ExecutionType.MARIA_DB) ? mariaConnectionUrl : cockroachUrl;
- connection = DriverManager.getConnection(url, connectionProps);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
- try {
- connection.setAutoCommit(false);
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
- return connection;
+ return BenchmarkUtils.getConnection(ip,type,user,password);
}
- private void createTable(Connection connection) {
- final String sql = "CREATE TABLE IF NOT EXISTS PERSONS (\n" +
- " PersonID int,\n" +
- " Counter int,\n" +
- " LastName varchar(255),\n" +
- " FirstName varchar(255),\n" +
- " Address varchar(255),\n" +
- " City varchar(255)\n" +
- ");";
-
- Statement stmt = null;
- try {
- stmt = connection.createStatement();
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
-
- Boolean execute = null;
- try {
- execute = stmt.execute(sql);
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
-
- try {
- connection.commit();
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
-
- try {
- stmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
-
- private boolean cleanTable() {
- String cleanCmd = "DELETE FROM PERSONS;";
- Statement stmt = null;
- try {
- stmt = testConnection.createStatement();
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
-
- Boolean execute = null;
- try {
- execute = stmt.execute(cleanCmd);
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
- try {
- testConnection.commit();
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
- try {
- stmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
- return execute;
- }
-
- private void addRowsToTable(int totalNumberOfRows) {
- for (int i = 0; i < totalNumberOfRows; i++) {
- final StringBuilder insertSQLBuilder = new StringBuilder()
- .append("INSERT INTO PERSONS VALUES (")
- .append(i)
- .append(", ")
- .append(0)
- .append(", '")
- .append("Last-")
- .append(i)
- .append("', '")
- .append("First-")
- .append(i)
- .append("', 'KACB', 'ATLANTA');");
- Statement stmt = null;
- try {
- stmt = testConnection.createStatement();
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
-
- Boolean execute = null;
- try {
- execute = stmt.execute(insertSQLBuilder.toString());
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
- try {
- stmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
- try {
- testConnection.commit();
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
+ @Setup(Level.Trial)
+ public void doTrialSetup(){
+ BenchmarkUtils.SetupTable(table);
+ update = BenchmarkUtils.updateBuilder;
}
@Setup(Level.Iteration)
public void doSetup() {
Connection connection = createConnection();
- createTable(connection);
- try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
+ setupCreateTables(connection);
//Setup connection
testConnection = createConnection();
- //Empty database
- boolean cleanResult = cleanTable();
- //Add new lines
- addRowsToTable(Integer.valueOf(rows));
+ setupCreateRows(testConnection,rows);
- //Commit
- try {
- testConnection.commit();
- } catch (SQLException e) {
- e.printStackTrace();
- System.exit(1);
- }
}
@TearDown(Level.Iteration)
diff --git a/mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricCommitBenchmark.java b/mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricCommitBenchmark.java
new file mode 100644
index 0000000..803a162
--- /dev/null
+++ b/mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricCommitBenchmark.java
@@ -0,0 +1,141 @@
+/*
+ * ============LICENSE_START====================================================
+ * org.onap.music.mdbc
+ * =============================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END======================================================
+ */
+package org.onap.music.mdbc;
+
+import static org.onap.music.mdbc.BenchmarkUtils.setupCreateRows;
+import static org.onap.music.mdbc.BenchmarkUtils.setupCreateTables;
+
+import org.onap.music.mdbc.BenchmarkUtils.ExecutionType;
+import org.openjdk.jmh.annotations.*;
+import org.openjdk.jmh.infra.Blackhole;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode({Mode.AverageTime, Mode.SampleTime})
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@State(Scope.Benchmark)
+public class MetricCommitBenchmark {
+
+
+ public static void main(String[] args) throws RunnerException {
+ Options opt = new OptionsBuilder()
+ .include(MetricBenchmark.class.getSimpleName())
+ .param("type", ExecutionType.METRIC.name())
+ .forks(1)
+ .threads(1)
+ .build();
+ new Runner(opt).run();
+ }
+
+ @Benchmark
+ public void testMethod(MyState state) {
+ try {
+ state.testConnection.commit();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+
+ @State(Scope.Benchmark)
+ public static class MyState {
+
+ String update;
+ final String user = "root";
+ final String password = "metriccluster";
+ @Param({"104.209.240.219"})
+ public String ip;
+ @Param({"1", "10", "50", "80", "100", "200", "300", "400"})
+ public int rows;
+ @Param({"MARIA_DB", "COCKROACH_DB", "METRIC","POSTGRES"})
+ public ExecutionType type;
+ @Param({"PERSONS"})
+ public String table;
+
+ public Connection testConnection;
+
+ public Statement stmt;
+
+ private Connection createConnection() {
+ return BenchmarkUtils.getConnection(ip,type,user,password);
+ }
+
+ @Setup(Level.Trial)
+ public void doTrialSetup(){
+ BenchmarkUtils.SetupTable(table);
+ update=BenchmarkUtils.updateBuilder;
+ }
+
+ @Setup(Level.Invocation)
+ public void doInvocationSetup(){
+ try {
+ stmt = testConnection.createStatement();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ Boolean execute = null;
+ try {
+ execute = stmt.execute(update);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ @TearDown(Level.Invocation)
+ public void doInvocationTearDown(){
+ try {
+ stmt.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ @Setup(Level.Iteration)
+ public void doSetup() {
+ Connection connection = createConnection();
+ setupCreateTables(connection);
+ //Setup connection
+ testConnection = createConnection();
+ setupCreateRows(testConnection,rows);
+ }
+
+ @TearDown(Level.Iteration)
+ public void doTearDown() {
+ System.out.println("Do TearDown");
+ try {
+ testConnection.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+ }
+}
diff --git a/mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricStatementBenchmark.java b/mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricStatementBenchmark.java
new file mode 100644
index 0000000..7dc950a
--- /dev/null
+++ b/mdbc-benchmark/src/main/java/org/onap/music/mdbc/MetricStatementBenchmark.java
@@ -0,0 +1,144 @@
+/*
+ * ============LICENSE_START====================================================
+ * org.onap.music.mdbc
+ * =============================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END======================================================
+ */
+package org.onap.music.mdbc;
+
+import static org.onap.music.mdbc.BenchmarkUtils.setupCreateRows;
+import static org.onap.music.mdbc.BenchmarkUtils.setupCreateTables;
+
+import org.onap.music.mdbc.BenchmarkUtils.ExecutionType;
+import org.openjdk.jmh.annotations.*;
+import org.openjdk.jmh.infra.Blackhole;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode({Mode.AverageTime, Mode.SampleTime})
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@State(Scope.Benchmark)
+public class MetricStatementBenchmark {
+
+
+ public static void main(String[] args) throws RunnerException {
+ Options opt = new OptionsBuilder()
+ .include(MetricBenchmark.class.getSimpleName())
+ .param("type", ExecutionType.METRIC.name())
+ .forks(1)
+ .threads(1)
+ .build();
+ new Runner(opt).run();
+ }
+
+ @Benchmark
+ public boolean testMethod(MyState state, Blackhole blackhole) {
+ Boolean execute = null;
+ try {
+ execute = state.stmt.execute(state.update);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ blackhole.consume(execute);
+ return execute;
+ }
+
+
+ @State(Scope.Benchmark)
+ public static class MyState {
+
+ public String update;
+ final String user = "root";
+ final String password = "metriccluster";
+ @Param({"104.209.240.219"})
+ public String ip;
+ @Param({"1", "10", "50", "80", "100", "200", "300", "400"})
+ public int rows;
+ @Param({"MARIA_DB", "COCKROACH_DB", "METRIC","POSTGRES"})
+ public ExecutionType type;
+ @Param({"PERSONS"})
+ public String table;
+
+ public Connection testConnection;
+
+ public Statement stmt;
+
+ private Connection createConnection() {
+ return BenchmarkUtils.getConnection(ip,type,user,password);
+ }
+
+ @Setup(Level.Trial)
+ public void doTrialSetup(){
+ BenchmarkUtils.SetupTable(table);
+ update=BenchmarkUtils.updateBuilder;
+ }
+
+ @Setup(Level.Invocation)
+ public void doInvocationSetup(){
+ try {
+ stmt = testConnection.createStatement();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ @TearDown(Level.Invocation)
+ public void doInvocationTearDown(){
+ try {
+ //TODO: check if state need to be consumed by blackhole to guarantee execution
+ testConnection.commit();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ try {
+ stmt.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ @Setup(Level.Iteration)
+ public void doSetup() {
+ Connection connection = createConnection();
+ setupCreateTables(connection);
+ //Setup connection
+ testConnection = createConnection();
+ setupCreateRows(testConnection,rows);
+ }
+
+ @TearDown(Level.Iteration)
+ public void doTearDown() {
+ System.out.println("Do TearDown");
+ try {
+ testConnection.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+ }
+}
diff --git a/mdbc-benchmark/src/main/resources/logback.xml b/mdbc-benchmark/src/main/resources/logback.xml
index e4d0030..4215681 100755
--- a/mdbc-benchmark/src/main/resources/logback.xml
+++ b/mdbc-benchmark/src/main/resources/logback.xml
@@ -37,7 +37,7 @@
-->
-<configuration scan="true" scanPeriod="3 seconds" debug="true">
+<configuration scan="false" scanPeriod="3 seconds" debug="true">
<!--
Logback files for the mdbc Driver "mdbc"
are created in directory ${catalina.base}/logs/mdbc;