Skip to content

Commit 3ecbe05

Browse files
author
Paultagoras
committed
Adjusting for cloud support
1 parent 124227f commit 3ecbe05

File tree

8 files changed

+102
-48
lines changed

8 files changed

+102
-48
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ profile.html
5555
**/test/resources/test.properties
5656
performance/jmh-simple-results.json
5757
*.csv
58+
*.sql

performance/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
<argument>-classpath</argument>
189189
<classpath />
190190
<argument>com.clickhouse.benchmark.BenchmarkRunner</argument>
191-
<argument>--dataset=file://dataset_1741150759025.csv</argument>
191+
<argument>--dataset=file://dataset_300k.csv</argument>
192192
<argument>.*</argument>
193193
</arguments>
194194
</configuration>

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.clickhouse.benchmark;
22

3-
4-
import com.clickhouse.benchmark.clients.BenchmarkBase;
53
import com.clickhouse.benchmark.clients.InsertClient;
64
import com.clickhouse.benchmark.clients.QueryClient;
75
import com.clickhouse.benchmark.data.DataSet;
@@ -20,6 +18,7 @@
2018
import java.util.Map;
2119
import java.util.concurrent.TimeUnit;
2220

21+
import static com.clickhouse.benchmark.clients.BenchmarkBase.DB_NAME;
2322

2423

2524
public class BenchmarkRunner {
@@ -39,9 +38,9 @@ public static void main(String[] args) throws Exception {
3938
.threads(1)
4039
.addProfiler(GCProfiler.class)
4140
.addProfiler(MemPoolProfiler.class)
42-
.warmupIterations(3)
41+
.warmupIterations(1)
4342
.warmupTime(TimeValue.seconds(10))
44-
.measurementIterations(5)
43+
.measurementIterations(3)
4544
.jvmArgs("-Xms8g", "-Xmx8g")
4645
.measurementTime(TimeValue.seconds(10))
4746
.resultFormat(ResultFormatType.JSON)
@@ -69,14 +68,18 @@ public static Map<String, String> parseArguments(String[] args) {
6968
}
7069

7170
public static String getSelectQuery(DataSet dataSet) {
72-
return "SELECT * FROM `" + BenchmarkBase.DB_NAME + "`.`" + dataSet.getTableName() + "`";
71+
return "SELECT * FROM `" + DB_NAME + "`.`" + dataSet.getTableName() + "`";
7372
}
7473

7574
public static String getSelectCountQuery(DataSet dataSet) {
76-
return "SELECT COUNT(*) FROM `" + BenchmarkBase.DB_NAME + "`.`" + dataSet.getTableName() + "`";
75+
return "SELECT COUNT(*) FROM `" + DB_NAME + "`.`" + dataSet.getTableName() + "`";
7776
}
7877

7978
public static String getInsertQuery(DataSet dataSet) {
80-
return "INSERT INTO `" + BenchmarkBase.DB_NAME + "`.`" + dataSet.getTableName() + "`";
79+
return "INSERT INTO `" + DB_NAME + "`.`" + dataSet.getTableName() + "`";
80+
}
81+
82+
public static String getSyncQuery(String tableName) {
83+
return String.format("SYSTEM SYNC REPLICA `%s`.`%s`", DB_NAME, tableName);
8184
}
8285
}

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

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.clickhouse.client.api.insert.InsertResponse;
1818
import com.clickhouse.client.api.internal.ServerSettings;
1919
import com.clickhouse.client.config.ClickHouseClientOption;
20+
import com.clickhouse.client.http.config.ClickHouseHttpOption;
2021
import com.clickhouse.data.ClickHouseDataProcessor;
2122
import com.clickhouse.client.api.query.GenericRecord;
2223
import com.clickhouse.data.ClickHouseFormat;
@@ -40,6 +41,9 @@
4041
import java.math.BigInteger;
4142
import java.util.List;
4243

44+
import static com.clickhouse.benchmark.BenchmarkRunner.getSelectCountQuery;
45+
import static com.clickhouse.benchmark.BenchmarkRunner.getSyncQuery;
46+
4347
@State(Scope.Benchmark)
4448
public class BenchmarkBase {
4549
private static final Logger LOGGER = LoggerFactory.getLogger(BenchmarkBase.class);
@@ -82,34 +86,42 @@ public void setup(DataState dataState, boolean insertData) throws Exception {
8286
dataState.datasetSourceName = "simple";
8387
dataState.dataSet = new SimpleDataSet();
8488
} else if (dataState.datasetSourceName.startsWith("file://")) {
89+
8590
dataState.dataSet = new FileDataSet(dataState.datasetSourceName.substring("file://".length()), dataState.limit);
8691
dataState.datasetSourceName = dataState.dataSet.getName();
8792
}
8893

8994
LOGGER.debug("BenchmarkBase setup(). Data source " + dataState.datasetSourceName);
90-
BaseIntegrationTest.setupClickHouseContainer();
95+
//BaseIntegrationTest.setupClickHouseContainer();
9196
runQuery("CREATE DATABASE IF NOT EXISTS " + DB_NAME, false);
9297
DataSets.initializeTables(dataState.dataSet, insertData);
98+
syncQuery(dataState.dataSet);
9399
}
94100

95101
public void tearDown() {
96102
runQuery("DROP DATABASE IF EXISTS " + DB_NAME, false);
97-
BaseIntegrationTest.teardownClickHouseContainer();
103+
//BaseIntegrationTest.teardownClickHouseContainer();
98104
}
99105

100106

101107
//Connection parameters
102108
public static boolean isCloud() {
103-
return false;
109+
return true;
104110
}
105111
public static String getPassword() {
106-
return ClickHouseServerForTest.getPassword();
112+
return "";
107113
}
108114
public static String getUsername() {
109115
return "default";
110116
}
111117
public static ClickHouseNode getServer() {
112-
return ClickHouseServerForTest.getClickHouseNode(ClickHouseProtocol.HTTP, isCloud(), ClickHouseNode.builder().build());
118+
return ClickHouseNode.builder(ClickHouseNode.builder().build())
119+
.address(ClickHouseProtocol.HTTP, new InetSocketAddress("", 8443))
120+
.credentials(ClickHouseCredentials.fromUserAndPassword(getUsername(), getPassword()))
121+
.options(Collections.singletonMap(ClickHouseClientOption.SSL.getKey(), "true"))
122+
.database(DB_NAME)
123+
.build();
124+
// return ClickHouseServerForTest.getClickHouseNode(ClickHouseProtocol.HTTP, isCloud(), ClickHouseNode.builder().build());
113125
}
114126
public static void isNotNull(Object obj, boolean doWeCare) {
115127
if (obj == null && doWeCare) {
@@ -123,10 +135,21 @@ public static List<GenericRecord> runQuery(String query, boolean useDatabase) {
123135
}
124136
}
125137

138+
public static void syncQuery(DataSet dataSet) {
139+
if (isCloud()) {
140+
LOGGER.debug("{}", getSyncQuery(dataSet.getTableName()));
141+
runQuery(getSyncQuery(dataSet.getTableName()), true);
142+
}
143+
}
144+
126145
public static void insertData(String tableName, InputStream dataStream, ClickHouseFormat format) {
127146
try (Client client = getClientV2();
128-
InsertResponse response = client.insert(tableName, dataStream, format).get()) {
129-
LOGGER.info("Rows inserted: {}", response.getWrittenRows());
147+
InsertResponse ignored = client.insert(tableName, dataStream, format).get()) {
148+
if (isCloud()) {
149+
runQuery(getSyncQuery(tableName), true);
150+
}
151+
List<GenericRecord> count = runQuery("SELECT COUNT(*) FROM `" + DB_NAME + "`.`" + tableName + "`", true);
152+
LOGGER.info("Rows written: {}", count.get(0).getBigInteger(1));
130153
} catch (Exception e) {
131154
LOGGER.error("Error inserting data: ", e);
132155
throw new RuntimeException("Error inserting data", e);
@@ -135,12 +158,14 @@ public static void insertData(String tableName, InputStream dataStream, ClickHou
135158

136159
public static void verifyRowsInsertedAndCleanup(DataSet dataSet) {
137160
try {
161+
syncQuery(dataSet);
138162
List<GenericRecord> records = runQuery(BenchmarkRunner.getSelectCountQuery(dataSet), true);
139163
BigInteger count = records.get(0).getBigInteger(1);
140164
if (count.longValue() != dataSet.getSize()) {
141165
throw new IllegalStateException("Rows written: " + count + " Expected " + dataSet.getSize() + " rows");
142166
}
143167
runQuery("TRUNCATE TABLE IF EXISTS `" + dataSet.getTableName() + "`", true);
168+
syncQuery(dataSet);
144169
} catch (Exception e) {
145170
LOGGER.error("Error: ", e);
146171
}
@@ -168,11 +193,11 @@ protected static Client getClientV2(boolean useDatabase) {
168193
}
169194

170195
public static void loadClickHouseRecords(DataSet dataSet) {
171-
ClickHouseNode node = getServer();
196+
syncQuery(dataSet);
172197

173-
try (ClickHouseClient clientV1 = ClickHouseClient
174-
.newInstance(ClickHouseCredentials.fromUserAndPassword(getUsername(), getPassword()), ClickHouseProtocol.HTTP);
175-
ClickHouseResponse response = clientV1.read(node).query(BenchmarkRunner.getSelectQuery(dataSet))
198+
try (ClickHouseClient clientV1 = getClientV1();
199+
ClickHouseResponse response = clientV1.read(getServer())
200+
.query(BenchmarkRunner.getSelectQuery(dataSet))
176201
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
177202
.executeAndWait()) {
178203

@@ -185,6 +210,7 @@ public static void loadClickHouseRecords(DataSet dataSet) {
185210
for (ClickHouseRecord record : response.records()) {
186211
records.add(record);
187212
}
213+
LOGGER.info("Rows read size: {}", records.size());
188214

189215
dataSet.setClickHouseRecords(records);
190216
} catch (Exception e) {

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

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import com.clickhouse.benchmark.BenchmarkRunner;
44
import com.clickhouse.client.ClickHouseResponse;
55
import com.clickhouse.client.ClickHouseResponseSummary;
6-
import com.clickhouse.client.api.Client;
7-
import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
86
import com.clickhouse.client.api.data_formats.RowBinaryFormatWriter;
9-
import com.clickhouse.client.api.enums.Protocol;
107
import com.clickhouse.client.api.insert.InsertResponse;
118
import com.clickhouse.client.api.insert.InsertSettings;
12-
import com.clickhouse.client.api.query.QueryResponse;
139
import com.clickhouse.client.config.ClickHouseClientOption;
10+
import com.clickhouse.client.http.config.ClickHouseHttpOption;
11+
import com.clickhouse.config.ClickHouseOption;
1412
import com.clickhouse.data.ClickHouseColumn;
1513
import com.clickhouse.data.ClickHouseDataProcessor;
1614
import com.clickhouse.data.ClickHouseFormat;
@@ -25,12 +23,9 @@
2523
import org.slf4j.Logger;
2624
import org.slf4j.LoggerFactory;
2725

28-
import java.math.BigInteger;
2926
import java.util.List;
3027
import java.util.Map;
3128

32-
import static com.clickhouse.client.ClickHouseServerForTest.isCloud;
33-
3429
@State(Scope.Benchmark)
3530
public class InsertClient extends BenchmarkBase {
3631
private static final Logger LOGGER = LoggerFactory.getLogger(InsertClient.class);
@@ -59,12 +54,8 @@ public void insertV1(DataState dataState) {
5954
for (byte[] bytes: dataState.dataSet.getBytesList(format)) {
6055
out.write(bytes);
6156
}
62-
})
63-
.executeAndWait()) {
64-
ClickHouseResponseSummary summary = response.getSummary();
65-
if (summary.getWrittenRows() != dataState.limit) {
66-
throw new IllegalStateException("Rows written: " + summary.getWrittenRows());
67-
}
57+
}).executeAndWait()) {
58+
response.getSummary();
6859
}
6960
} catch (Exception e) {
7061
LOGGER.error("Error: ", e);
@@ -82,9 +73,7 @@ public void insertV2(DataState dataState) {
8273
}
8374
out.close();
8475
}, format, new InsertSettings()).get()) {
85-
if (response.getWrittenRows() != dataState.limit) {
86-
throw new IllegalStateException("Rows written: " + response.getWrittenRows() + ", expected: " + dataState.limit);
87-
}
76+
response.getWrittenRows();
8877
}
8978
} catch (Exception e) {
9079
LOGGER.error("Error: ", e);
@@ -112,10 +101,7 @@ public void insertV1RowBinary(DataState dataState) {
112101

113102
})
114103
.executeAndWait()) {
115-
ClickHouseResponseSummary summary = response.getSummary();
116-
if (summary.getWrittenRows() != dataState.limit) {
117-
throw new RuntimeException("Rows written: " + summary.getWrittenRows() + ", expected: " + dataState.limit);
118-
}
104+
response.getSummary();
119105
}
120106
} catch ( Exception e) {
121107
LOGGER.error("Error: ", e);
@@ -137,9 +123,7 @@ public void insertV2RowBinary(DataState dataState) {
137123
out.flush();
138124

139125
}, ClickHouseFormat.RowBinaryWithDefaults, new InsertSettings()).get()) {
140-
if (response.getWrittenRows() != dataState.limit) {
141-
throw new RuntimeException("Rows written: " + response.getWrittenRows() + ", expected: " + dataState.limit);
142-
}
126+
response.getWrittenRows();
143127
}
144128
} catch (Exception e) {
145129
LOGGER.error("Error: ", e);

performance/src/test/com/clickhouse/benchmark/data/DataSets.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
import java.util.Map;
1515
import java.util.stream.Collectors;
1616

17+
import static com.clickhouse.benchmark.clients.BenchmarkBase.insertData;
18+
import static com.clickhouse.benchmark.clients.BenchmarkBase.loadClickHouseRecords;
19+
import static com.clickhouse.benchmark.clients.BenchmarkBase.runQuery;
20+
import static com.clickhouse.benchmark.clients.BenchmarkBase.syncQuery;
21+
1722
public class DataSets {
1823
private static final Logger LOGGER = LoggerFactory.getLogger(DataSets.class);
1924
private static final Map<String, DataSet> sets;
@@ -58,13 +63,14 @@ public static TableSchema parseSchema(String createTableStatement) {//TODO: Cons
5863
}
5964

6065
public static void initializeTables(DataSet set, boolean insertData) {
61-
BenchmarkBase.runQuery(set.getCreateTableString(), true);
66+
runQuery(set.getCreateTableString(), true);
6267
ClickHouseFormat format = set.getFormat();
6368

64-
BenchmarkBase.insertData(set.getTableName(), set.getInputStream(format), format);
69+
insertData(set.getTableName(), set.getInputStream(format), format);
6570
if (!insertData) {
66-
BenchmarkBase.loadClickHouseRecords(set);
67-
BenchmarkBase.runQuery("TRUNCATE TABLE " + set.getTableName(), true);
71+
loadClickHouseRecords(set);
72+
runQuery("TRUNCATE TABLE " + set.getTableName(), true);
73+
syncQuery(set);
6874
}
6975
}
7076

performance/src/test/com/clickhouse/benchmark/data/FileDataSet.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class FileDataSet implements DataSet{
3434
private List<Map<String, Object>> data;
3535

3636
public FileDataSet(String filePath, int limit) {
37+
LOGGER.info("Reading file {}", filePath);
3738
File srcFile = new File(filePath);
3839

3940
try (BufferedReader r = new BufferedReader(new java.io.FileReader(srcFile))) {
@@ -73,13 +74,11 @@ public FileDataSet(String filePath, int limit) {
7374
} else {
7475
throw new IllegalArgumentException("Invalid file format: " + srcFile.getAbsolutePath());
7576
}
76-
7777
}
7878
this.name = name;
7979
this.createTableStmt = createStatement != null ? createStatement.toString() : null;
8080
this.schema = DataSets.parseSchema(createTableStmt);
8181
LOGGER.info("Read " + lines.size() + " lines from " + srcFile.getAbsolutePath());
82-
8382
} catch (Exception e) {
8483
throw new IllegalArgumentException("Failed to read file: " + srcFile.getAbsolutePath(), e);
8584
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SLF4J's SimpleLogger configuration file
2+
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
3+
4+
# Default logging detail level for all instances of SimpleLogger.
5+
# Must be one of ("trace", "debug", "info", "warn", or "error").
6+
# If not specified, defaults to "info".
7+
#org.slf4j.simpleLogger.defaultLogLevel=error
8+
org.slf4j.simpleLogger.defaultLogLevel=info
9+
10+
# Logging detail level for a SimpleLogger instance named "xxxxx".
11+
# Must be one of ("trace", "debug", "info", "warn", or "error").
12+
# If not specified, the default logging detail level is used.
13+
#org.slf4j.simpleLogger.log.xxxxx=
14+
15+
# Set to true if you want the current date and time to be included in output messages.
16+
# Default is false, and will output the number of milliseconds elapsed since startup.
17+
#org.slf4j.simpleLogger.showDateTime=false
18+
19+
# The date and time format to be used in the output messages.
20+
# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
21+
# If the format is not specified or is invalid, the default format is used.
22+
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
23+
#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
24+
25+
# Set to true if you want to output the current thread name.
26+
# Defaults to true.
27+
#org.slf4j.simpleLogger.showThreadName=true
28+
29+
# Set to true if you want the Logger instance name to be included in output messages.
30+
# Defaults to true.
31+
#org.slf4j.simpleLogger.showLogName=true
32+
33+
# Set to true if you want the last component of the name to be included in output messages.
34+
# Defaults to false.
35+
#org.slf4j.simpleLogger.showShortLogName=false

0 commit comments

Comments
 (0)