Skip to content

Commit

Permalink
Update benchmarks to cover more data types
Browse files Browse the repository at this point in the history
  • Loading branch information
zhicwu committed Nov 29, 2021
1 parent 1ee8668 commit 395bc03
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.clickhouse.benchmark.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.openjdk.jmh.infra.Blackhole;

@FunctionalInterface
public interface ConsumeValueFunction {
void consume(Blackhole blackhole, ResultSet rs, int columnIndex) throws SQLException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
Expand All @@ -18,7 +19,7 @@
@State(Scope.Thread)
public class DriverState extends BaseState {
@Param(value = { "clickhouse4j", "clickhouse-http-jdbc", "clickhouse-grpc-jdbc", "clickhouse-jdbc",
"clickhouse-native-jdbc-shaded", "mariadb-java-client", "mysql-connector-java", "postgresql-jdbc" })
"clickhouse-native-jdbc", "mariadb-java-client", "mysql-connector-java", "postgresql-jdbc" })
private String client;

@Param(value = { Constants.REUSE_CONNECTION, Constants.NEW_CONNECTION })
Expand All @@ -27,6 +28,9 @@ public class DriverState extends BaseState {
@Param(value = { Constants.NORMAL_STATEMENT, Constants.PREPARED_STATEMENT })
private String statement;

@Param(value = { "default", "string", "object" })
private String type;

private Driver driver;
private String url;
private Connection conn;
Expand Down Expand Up @@ -113,4 +117,16 @@ public Connection getConnection() throws SQLException {
public boolean usePreparedStatement() {
return Constants.PREPARED_STATEMENT.equalsIgnoreCase(this.statement);
}

public ConsumeValueFunction getConsumeFunction(ConsumeValueFunction defaultFunc) {
if ("string".equals(type)) {
return (b, r, i) -> b.consume(r.getString(i));
} else if ("object".equals(type)) {
return (b, r, i) -> b.consume(r.getObject(i));
} else if (defaultFunc == null) {
return (b, r, i) -> b.consume(i);
} else {
return defaultFunc;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum JdbcDriver {
"jdbc:clickhouse://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
Constants.HTTP_PORT),
// ClickHouse Native JDBC Driver
ClickhouseNativeJdbcShaded("com.github.housepower.jdbc.ClickHouseDriver",
ClickhouseNativeJdbc("com.github.housepower.jdbc.ClickHouseDriver",
"jdbc:clickhouse://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
Constants.NATIVE_PORT),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,151 @@

public class Query extends DriverBenchmark {
@Benchmark
public void selectDateTime32Rows(Blackhole blackhole, DriverState state) throws Throwable {
public void selectArrayOfInts(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getArray(i)));
try (Statement stmt = executeQuery(state,
"select toDateTime32(1613826920 + number) as d from system.numbers limit ?", rows)) {
"select range(100, number % 600) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
blackhole.consume(rs.getTimestamp(1));
func.consume(blackhole, rs, 1);
}
}
}

@Benchmark
public void selectDateTime64Rows(Blackhole blackhole, DriverState state) throws Throwable {
public void selectMapOfInts(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getObject(i)));
try (Statement stmt = executeQuery(state,
"select toDateTime64(1613826920 + number / 1000000000, 9) as d from system.numbers limit ?", rows)) {
"select cast((arrayMap(x->x+1000, range(1, number % 100)), arrayMap(x->x+10000, range(1, number %100))) as Map(Int32, Int32)) as v from numbers(?)",
rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
blackhole.consume(rs.getTimestamp(1));
func.consume(blackhole, rs, 1);
}
}
}

@Benchmark
public void selectDateTime64ObjectRows(Blackhole blackhole, DriverState state) throws Throwable {
public void selectTupleOfInts(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getArray(i)));
try (Statement stmt = executeQuery(state,
"select toDateTime64(1613826920 + number / 1000000000, 9) as d from system.numbers limit ?", rows)) {
"select tuple(range(100, number % 600)) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
blackhole.consume(rs.getObject(1));
func.consume(blackhole, rs, 1);
}
}
}

@Benchmark
public void selectInt32Rows(Blackhole blackhole, DriverState state) throws Throwable {
public void selectDateTime32(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
try (Statement stmt = executeQuery(state, "select toInt32(number) from system.numbers limit ?", rows)) {
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getTimestamp(i)));
try (Statement stmt = executeQuery(state,
"select toDateTime32(1613826920 + number) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
}
}
}

@Benchmark
public void selectDateTime64(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getTimestamp(i)));
try (Statement stmt = executeQuery(state,
"select toDateTime64(1613826920 + number / 1000000000, 9) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
}
}
}

@Benchmark
public void selectInt8(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getByte(i)));
try (Statement stmt = executeQuery(state, "select toInt8(number % 256) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
}
}
}

@Benchmark
public void selectUInt8(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getShort(i)));
try (Statement stmt = executeQuery(state, "select toUInt8(number % 256) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
}
}
}

@Benchmark
public void selectInt32(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getInt(i)));
try (Statement stmt = executeQuery(state, "select toInt32(number) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
func.consume(blackhole, rs, 1);
}
}
}

@Benchmark
public void selectString(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getString(i)));
try (Statement stmt = executeQuery(state, "select toString(number/3) as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
blackhole.consume(rs.getInt(1));
func.consume(blackhole, rs, 1);
}
}
}

@Benchmark
public void selectStringRows(Blackhole blackhole, DriverState state) throws Throwable {
public void selectUInt64(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
try (Statement stmt = executeQuery(state, "select toString(number) as s from system.numbers limit ?", rows)) {
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getLong(i)));
try (Statement stmt = executeQuery(state, "select number as v from numbers(?)", rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
blackhole.consume(rs.getString(1));
func.consume(blackhole, rs, 1);
}
}
}

@Benchmark
public void selectUInt64Rows(Blackhole blackhole, DriverState state) throws Throwable {
public void selectDecimal64(Blackhole blackhole, DriverState state) throws Throwable {
int num = state.getRandomNumber();
int rows = state.getSampleSize() + num;
try (Statement stmt = executeQuery(state, "select * from system.numbers limit ?", rows)) {
ConsumeValueFunction func = state.getConsumeFunction((b, r, i) -> b.consume(r.getBigDecimal(i)));
try (Statement stmt = executeQuery(state, "select toDecimal64(number + number / 10000, 4) as v from numbers(?)",
rows)) {
ResultSet rs = stmt.getResultSet();
while (rs.next()) {
blackhole.consume(rs.getLong(1));
func.consume(blackhole, rs, 1);
}
}
}
Expand Down

0 comments on commit 395bc03

Please sign in to comment.