Skip to content

Commit b848f72

Browse files
authored
Merge branch 'main' into perf_typed_tests
2 parents 8f1b22d + 892599e commit b848f72

File tree

5 files changed

+150
-12
lines changed

5 files changed

+150
-12
lines changed

performance/src/test/com/clickhouse/benchmark/BenchmarkRunner.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.clickhouse.benchmark.clients.ConcurrentQueryClient;
77
import com.clickhouse.benchmark.clients.Deserializers;
88
import com.clickhouse.benchmark.clients.InsertClient;
9+
import com.clickhouse.benchmark.clients.JDBCInsert;
10+
import com.clickhouse.benchmark.clients.JDBCQuery;
911
import com.clickhouse.benchmark.clients.MixedWorkload;
1012
import com.clickhouse.benchmark.clients.QueryClient;
1113
import com.clickhouse.benchmark.clients.Serializers;
@@ -39,13 +41,15 @@ public static void main(String[] args) throws Exception {
3941
Options opt = new OptionsBuilder()
4042
.include(QueryClient.class.getName())
4143
.include(InsertClient.class.getName())
42-
// .include(ConcurrentInsertClient.class.getSimpleName())
43-
.include(ConcurrentQueryClient.class.getSimpleName())
44+
.include(ConcurrentInsertClient.class.getName())
45+
.include(ConcurrentQueryClient.class.getName())
4446
.include(Compression.class.getName())
4547
.include(Serializers.class.getName())
4648
.include(Deserializers.class.getName())
4749
.include(MixedWorkload.class.getName())
48-
// .include(DataTypes.class.getName())
50+
.include(DataTypes.class.getName())
51+
.include(JDBCQuery.class.getName())
52+
.include(JDBCInsert.class.getName())
4953
.forks(1) // must be a fork. No fork only for debugging
5054
.mode(Mode.SampleTime)
5155
.timeUnit(TimeUnit.MILLISECONDS)

performance/src/test/com/clickhouse/benchmark/clients/BenchmarkBase.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.clickhouse.client.ClickHouseNodeSelector;
1313
import com.clickhouse.client.ClickHouseProtocol;
1414
import com.clickhouse.client.ClickHouseResponse;
15+
import com.clickhouse.client.ClickHouseServerForTest;
1516
import com.clickhouse.client.api.Client;
1617
import com.clickhouse.client.api.ConnectionReuseStrategy;
1718
import com.clickhouse.client.api.enums.Protocol;
@@ -23,6 +24,7 @@
2324
import com.clickhouse.data.ClickHouseOutputStream;
2425
import com.clickhouse.data.ClickHouseRecord;
2526
import com.clickhouse.data.format.ClickHouseRowBinaryProcessor;
27+
import com.clickhouse.jdbc.ClickHouseDriver;
2628
import org.openjdk.jmh.annotations.Level;
2729
import org.openjdk.jmh.annotations.Param;
2830
import org.openjdk.jmh.annotations.Scope;
@@ -36,9 +38,12 @@
3638
import java.io.InputStream;
3739
import java.math.BigInteger;
3840
import java.nio.ByteBuffer;
41+
import java.sql.Connection;
42+
import java.sql.SQLException;
3943
import java.util.ArrayList;
4044
import java.util.Collections;
4145
import java.util.List;
46+
import java.util.Properties;
4247

4348
import static com.clickhouse.benchmark.BenchmarkRunner.getSelectCountQuery;
4449
import static com.clickhouse.benchmark.BenchmarkRunner.getSyncQuery;
@@ -53,14 +58,18 @@
5358
@State(Scope.Benchmark)
5459
public class BenchmarkBase {
5560
private static final Logger LOGGER = LoggerFactory.getLogger(BenchmarkBase.class);
56-
5761
protected ClickHouseClient clientV1;
5862
protected Client clientV2;
63+
protected static Connection jdbcV1;
64+
protected static Connection jdbcV2;
65+
5966
@Setup(Level.Iteration)
6067
public void setUpIteration() {
6168
LOGGER.info("BenchmarkBase::setUpIteration");
6269
clientV1 = getClientV1();
6370
clientV2 = getClientV2();
71+
jdbcV1 = getJdbcV1();
72+
jdbcV2 = getJdbcV2();
6473
}
6574

6675
@TearDown(Level.Iteration)
@@ -74,6 +83,22 @@ public void tearDownIteration() {
7483
clientV2.close();
7584
clientV2 = null;
7685
}
86+
if (jdbcV1 != null) {
87+
try {
88+
jdbcV1.close();
89+
} catch (SQLException e) {
90+
LOGGER.error(e.getMessage());
91+
}
92+
jdbcV1 = null;
93+
}
94+
if (jdbcV2 != null) {
95+
try {
96+
jdbcV2.close();
97+
} catch (SQLException e) {
98+
LOGGER.error(e.getMessage());
99+
}
100+
jdbcV2 = null;
101+
}
77102
}
78103

79104
@State(Scope.Benchmark)
@@ -244,6 +269,37 @@ protected static Client getClientV2(boolean includeDb) {
244269
.setDefaultDatabase(includeDb ? DB_NAME : "default")
245270
.build();
246271
}
272+
273+
protected static Connection getJdbcV1() {
274+
Properties properties = new Properties();
275+
properties.put("user", getUsername());
276+
properties.put("password", getPassword());
277+
278+
ClickHouseNode node = getServer();
279+
Connection jdbcV1 = null;
280+
try {
281+
jdbcV1 = new ClickHouseDriver().connect(String.format("jdbc:clickhouse://%s:%s?clickhouse.jdbc.v1=true", node.getHost(), node.getPort()), properties);
282+
} catch (SQLException e) {
283+
LOGGER.error(e.getMessage());
284+
}
285+
return jdbcV1;
286+
}
287+
288+
protected static Connection getJdbcV2() {
289+
Properties properties = new Properties();
290+
properties.put("user", getUsername());
291+
properties.put("password", getPassword());
292+
293+
ClickHouseNode node = getServer();
294+
Connection jdbcV2 = null;
295+
try {
296+
jdbcV2 = new ClickHouseDriver().connect(String.format("jdbc:clickhouse://%s:%s", node.getHost(), node.getPort()), properties);
297+
} catch (SQLException e) {
298+
LOGGER.error(e.getMessage());
299+
}
300+
301+
return jdbcV2;
302+
}
247303

248304
public static void loadClickHouseRecords(DataState dataState) {
249305
syncQuery(dataState.tableNameFilled);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.clickhouse.benchmark.clients;
2+
3+
import org.openjdk.jmh.annotations.Benchmark;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
7+
import java.sql.Connection;
8+
import java.sql.PreparedStatement;
9+
import java.sql.SQLException;
10+
import java.util.List;
11+
import java.util.stream.Collectors;
12+
13+
import static com.clickhouse.benchmark.TestEnvironment.DB_NAME;
14+
15+
public class JDBCInsert extends BenchmarkBase {
16+
private static final Logger LOGGER = LoggerFactory.getLogger(JDBCInsert.class);
17+
void insetData(Connection connection, DataState dataState) throws SQLException {
18+
int size = dataState.dataSet.getSchema().getColumns().size();
19+
String names = dataState.dataSet.getSchema().getColumns().stream().map(column -> column.getColumnName()).collect(Collectors.joining(","));
20+
String values = dataState.dataSet.getSchema().getColumns().stream().map(column -> "?").collect(Collectors.joining(","));
21+
String sql = String.format("INSERT INTO `%s`.`%s` (%s) VALUES (%s)", DB_NAME ,dataState.tableNameEmpty, names, values);
22+
LOGGER.info("SQL: " + sql);
23+
PreparedStatement preparedStatement = connection.prepareStatement(sql);
24+
for (List<Object> data : dataState.dataSet.getRowsOrdered()) {
25+
for (int j = 0; j < size; j++) {
26+
preparedStatement.setObject(j + 1, data.get(j));
27+
}
28+
preparedStatement.addBatch();
29+
}
30+
preparedStatement.executeBatch();
31+
}
32+
33+
@Benchmark
34+
public void insertJDBCV1(DataState dataState) throws SQLException {
35+
insetData(jdbcV1, dataState);
36+
}
37+
38+
@Benchmark
39+
public void insertJDBCV2(DataState dataState) throws SQLException {
40+
insetData(jdbcV2, dataState);
41+
}
42+
43+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.clickhouse.benchmark.clients;
2+
3+
import org.openjdk.jmh.annotations.Benchmark;
4+
import org.openjdk.jmh.infra.Blackhole;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
import java.sql.Connection;
9+
import java.sql.ResultSet;
10+
import java.sql.SQLException;
11+
import java.sql.Statement;
12+
13+
import static com.clickhouse.benchmark.BenchmarkRunner.getSelectQuery;
14+
15+
public class JDBCQuery extends BenchmarkBase {
16+
private static final Logger LOGGER = LoggerFactory.getLogger(JDBCQuery.class);
17+
void selectData(Connection connection, DataState dataState, Blackhole blackhole) throws SQLException {
18+
String sql = getSelectQuery(dataState.tableNameFilled);
19+
try (Statement stmt = connection.createStatement()) {
20+
try (ResultSet rs = stmt.executeQuery(sql)) {
21+
while (rs.next()) {
22+
for (int i = 1; i <= dataState.dataSet.getSchema().getColumns().size(); i++) {
23+
blackhole.consume(rs.getObject(i));
24+
}
25+
}
26+
}
27+
}
28+
}
29+
30+
@Benchmark
31+
public void selectJDBCV1(DataState dataState, Blackhole blackhole) throws SQLException {
32+
selectData(jdbcV1, dataState, blackhole);
33+
}
34+
35+
@Benchmark
36+
public void selectJDBCV2(DataState dataState, Blackhole blackhole) throws SQLException {
37+
selectData(jdbcV2, dataState, blackhole);
38+
}
39+
40+
}

performance/src/test/com/clickhouse/benchmark/clients/MixedWorkload.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
@State(Scope.Benchmark)
3636
public class MixedWorkload extends BenchmarkBase {
3737
private static final Logger LOGGER = LoggerFactory.getLogger(MixedWorkload.class);
38+
private static final int LIMIT = 10000;
3839

3940
private ClickHouseClient clientV1Shared;
4041
private Client clientV2Shared;
@@ -56,12 +57,6 @@ public void tearDownTrial() {
5657
}
5758
}
5859

59-
// @State(Scope.Thread)
60-
// public static class MixedWorkloadState {
61-
// @Param({"true", "false"})
62-
// public boolean alternate;
63-
// }
64-
6560

6661
@TearDown(Level.Iteration)
6762
public void teardownIteration(DataState dataState) {
@@ -124,7 +119,7 @@ public void insertV1RowBinary(DataState dataState) {
124119
public void queryV1(DataState dataState, Blackhole blackhole) {
125120
try {
126121
try (ClickHouseResponse response = clientV1Shared.read(getServer())
127-
.query(BenchmarkRunner.getSelectQuery(dataState.tableNameFilled))
122+
.query(BenchmarkRunner.getSelectQueryWithLimit(dataState.tableNameFilled, LIMIT))
128123
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
129124
.option(ClickHouseClientOption.ASYNC, false)
130125
.executeAndWait()) {
@@ -190,7 +185,7 @@ public void insertV2RowBinary(DataState dataState) {
190185
@Group("mixed_v2")
191186
public void queryV2(DataState dataState, Blackhole blackhole) {
192187
try {
193-
try(QueryResponse response = clientV2Shared.query(BenchmarkRunner.getSelectQuery(dataState.tableNameFilled)).get()) {
188+
try(QueryResponse response = clientV2Shared.query(BenchmarkRunner.getSelectQueryWithLimit(dataState.tableNameFilled, LIMIT)).get()) {
194189
ClickHouseBinaryFormatReader reader = clientV2Shared.newBinaryFormatReader(response);
195190
while (reader.next() != null) {//Compiler optimization avoidance
196191
for (int i = 1; i <= dataState.dataSet.getSchema().getColumns().size(); i++) {

0 commit comments

Comments
 (0)