Skip to content

Commit c467990

Browse files
author
Paultagoras
committed
Adding rudimentary table schema generation and query changes
1 parent 645f3a5 commit c467990

File tree

10 files changed

+167
-298
lines changed

10 files changed

+167
-298
lines changed

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
package com.clickhouse.benchmark;
22

3-
import com.clickhouse.benchmark.clients.ClientV1;
4-
import com.clickhouse.benchmark.clients.ClientV2;
3+
54
import com.clickhouse.benchmark.clients.InsertClient;
6-
import com.clickhouse.benchmark.clients.JdbcV1;
7-
import com.clickhouse.benchmark.clients.JdbcV2;
8-
import com.clickhouse.benchmark.data.DataSet;
9-
import com.clickhouse.benchmark.data.DataSets;
10-
import com.clickhouse.benchmark.data.SimpleDataSet;
11-
import com.clickhouse.client.BaseIntegrationTest;
12-
import com.clickhouse.client.ClickHouseNode;
13-
import com.clickhouse.client.ClickHouseProtocol;
14-
import com.clickhouse.client.ClickHouseServerForTest;
15-
import com.clickhouse.client.api.Client;
16-
import com.clickhouse.client.api.enums.Protocol;
17-
import com.clickhouse.client.api.metadata.TableSchema;
18-
import com.clickhouse.data.ClickHouseFormat;
5+
import com.clickhouse.benchmark.clients.QueryClient;
196
import org.openjdk.jmh.annotations.Mode;
207
import org.openjdk.jmh.profile.GCProfiler;
218
import org.openjdk.jmh.profile.MemPoolProfiler;
@@ -42,11 +29,8 @@ public static void main(String[] args) throws Exception {
4229

4330
Options opt = new OptionsBuilder()
4431
.param("datasetSourceName", argMap.getOrDefault("dataset", "simple"))
45-
// .include(ClientV1.class.getSimpleName())
46-
// .include(ClientV2.class.getSimpleName())
32+
.include(QueryClient.class.getSimpleName())
4733
.include(InsertClient.class.getSimpleName())
48-
// .include(JdbcV1.class.getSimpleName())
49-
// .include(JdbcV2.class.getSimpleName())
5034
.forks(1) // must be a fork. No fork only for debugging
5135
.mode(Mode.AverageTime)
5236
.timeUnit(TimeUnit.MILLISECONDS)

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

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.clickhouse.benchmark.data.FileDataSet;
66
import com.clickhouse.benchmark.data.SimpleDataSet;
77
import com.clickhouse.client.BaseIntegrationTest;
8+
import com.clickhouse.client.ClickHouseClient;
9+
import com.clickhouse.client.ClickHouseCredentials;
810
import com.clickhouse.client.ClickHouseNode;
911
import com.clickhouse.client.ClickHouseProtocol;
1012
import com.clickhouse.client.ClickHouseServerForTest;
@@ -67,39 +69,46 @@ public static String getUsername() {
6769
public static ClickHouseNode getServer() {
6870
return ClickHouseServerForTest.getClickHouseNode(ClickHouseProtocol.HTTP, isCloud(), ClickHouseNode.builder().build());
6971
}
70-
public static void notNull(Object obj) {
71-
if (obj == null) {
72-
throw new IllegalStateException("Null value");
72+
public static void isNotNull(Object obj, boolean doWeCare) {
73+
if (obj == null && doWeCare) {
74+
throw new RuntimeException("Object is null");
7375
}
7476
}
7577

7678
public static void runQuery(String query, boolean useDatabase) {
77-
ClickHouseNode node = getServer();
78-
try (Client client = new Client.Builder()
79-
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud())
80-
.setUsername(getUsername())
81-
.setPassword(getPassword())
82-
.compressClientRequest(true)
83-
.setDefaultDatabase(useDatabase ? DB_NAME : "default")
84-
.build()) {
79+
try (Client client = getClientV2(useDatabase)) {
8580
client.queryAll(query);
8681
}
8782
}
8883

8984
public static void insertData(String tableName, InputStream dataStream, ClickHouseFormat format) {
90-
ClickHouseNode node = getServer();
91-
try (Client client = new Client.Builder()
92-
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud())
93-
.setUsername(getUsername())
94-
.setPassword(getPassword())
95-
.compressClientRequest(true)
96-
.setDefaultDatabase(DB_NAME)
97-
.build();
85+
try (Client client = getClientV2();
9886
InsertResponse response = client.insert(tableName, dataStream, format).get()) {
9987
LOGGER.info("Rows inserted: {}", response.getWrittenRows());
10088
} catch (Exception e) {
10189
LOGGER.error("Error inserting data: ", e);
10290
throw new RuntimeException("Error inserting data", e);
10391
}
10492
}
93+
94+
protected static ClickHouseClient getClientV1() {
95+
//We get a new client so that closing won't affect other subsequent calls
96+
return ClickHouseClient.newInstance(ClickHouseCredentials.fromUserAndPassword(getUsername(), getPassword()), ClickHouseProtocol.HTTP);
97+
}
98+
99+
protected static Client getClientV2() {
100+
return getClientV2(true);
101+
}
102+
protected static Client getClientV2(boolean useDatabase) {
103+
ClickHouseNode node = getServer();
104+
//We get a new client so that closing won't affect other subsequent calls
105+
return new Client.Builder()
106+
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud())
107+
.setUsername(getUsername())
108+
.setPassword(getPassword())
109+
.compressClientRequest(true)
110+
.setMaxRetries(0)
111+
.setDefaultDatabase(useDatabase ? DB_NAME : "default")
112+
.build();
113+
}
105114
}

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

Lines changed: 0 additions & 117 deletions
This file was deleted.

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

Lines changed: 0 additions & 103 deletions
This file was deleted.

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,8 @@ public void setup(DataState dataState) throws Exception {
4444
@Setup(Level.Iteration)
4545
public void setUpIteration() {
4646
LOGGER.info("Setup Each Invocation");
47-
clientV1 = ClickHouseClient
48-
.newInstance(ClickHouseCredentials.fromUserAndPassword(getUsername(), getPassword()), ClickHouseProtocol.HTTP);
49-
ClickHouseNode node = getServer();
50-
clientV2 = new Client.Builder()
51-
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud())
52-
.setUsername(getUsername())
53-
.setPassword(getPassword())
54-
.compressClientRequest(true)
55-
.setMaxRetries(0)
56-
.setDefaultDatabase(DB_NAME)
57-
.build();
47+
clientV1 = getClientV1();
48+
clientV2 = getClientV2();
5849

5950
}
6051

@@ -72,7 +63,7 @@ public void tearDownIteration() {
7263

7364
@TearDown(Level.Invocation)
7465
public void tearDownIteration(DataState dataState) throws InterruptedException {
75-
try {
66+
try (Client clientV2 = getClientV2()) {
7667
try(QueryResponse response = clientV2.query("SELECT count(*) FROM `" + dataState.dataSet.getTableName() + "`").get()) {
7768
ClickHouseBinaryFormatReader reader = clientV2.newBinaryFormatReader(response);
7869
while (reader.next() != null) {//Compiler optimization avoidance
@@ -92,15 +83,10 @@ public void tearDownIteration(DataState dataState) throws InterruptedException {
9283
LOGGER.error("Error: ", e);
9384
}
9485
}
95-
@State(Scope.Thread)
96-
public static class InsertState {
97-
@Param({"simple"})
98-
String dataSetName;
99-
ClickHouseFormat format = ClickHouseFormat.JSONEachRow;
100-
}
86+
10187

10288
@Benchmark
103-
public void insertV1(DataState dataState, InsertState state) {
89+
public void insertV1(DataState dataState) {
10490
try {
10591
ClickHouseFormat format = dataState.dataSet.getFormat();
10692
try (ClickHouseResponse response = clientV1.read(getServer())
@@ -125,7 +111,7 @@ public void insertV1(DataState dataState, InsertState state) {
125111
}
126112

127113
@Benchmark
128-
public void insertV2(DataState dataState, InsertState state) {
114+
public void insertV2(DataState dataState) {
129115
try {
130116
ClickHouseFormat format = dataState.dataSet.getFormat();
131117
try (InsertResponse response = clientV2.insert(dataState.dataSet.getTableName(), out -> {

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

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)