Skip to content

Commit 5945902

Browse files
authored
Small fixes benchmark (#2246)
* Adding method to verify the number rows inserted * Fix jdbcURL for cloud * set back warmup iterations to 3
1 parent 892599e commit 5945902

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static void main(String[] args) throws Exception {
5353
.timeUnit(TimeUnit.MILLISECONDS)
5454
.addProfiler(GCProfiler.class)
5555
.addProfiler(MemPoolProfiler.class)
56-
.warmupIterations(1)
56+
.warmupIterations(3)
5757
.warmupTime(TimeValue.seconds(5))
5858
.measurementIterations(10)
5959
.jvmArgs("-Xms8g", "-Xmx8g")

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,32 @@ protected static Client getClientV2(boolean includeDb) {
265265
.setDefaultDatabase(includeDb ? DB_NAME : "default")
266266
.build();
267267
}
268-
268+
private static String jdbcURLV1(boolean isCloud) {
269+
ClickHouseNode node = getServer();
270+
if (isCloud) {
271+
return String.format("jdbc:clickhouse://%s:%s?clickhouse.jdbc.v1=true&ssl=true", node.getHost(), node.getPort());
272+
} else
273+
return String.format("jdbc:clickhouse://%s:%s?clickhouse.jdbc.v1=true", node.getHost(), node.getPort());
274+
}
275+
276+
private static String jdbcURLV2(boolean isCloud) {
277+
ClickHouseNode node = getServer();
278+
if (isCloud) {
279+
return String.format("jdbc:clickhouse://%s:%s?ssl=true", node.getHost(), node.getPort());
280+
} else
281+
return String.format("jdbc:clickhouse://%s:%s", node.getHost(), node.getPort());
282+
}
283+
269284
protected static Connection getJdbcV1() {
270285
Properties properties = new Properties();
271286
properties.put("user", getUsername());
272287
properties.put("password", getPassword());
273-
274-
ClickHouseNode node = getServer();
288+
275289
Connection jdbcV1 = null;
290+
String jdbcURL = jdbcURLV1(isCloud());
291+
LOGGER.info("JDBC URL: " + jdbcURL);
276292
try {
277-
jdbcV1 = new ClickHouseDriver().connect(String.format("jdbc:clickhouse://%s:%s?clickhouse.jdbc.v1=true", node.getHost(), node.getPort()), properties);
293+
jdbcV1 = new ClickHouseDriver().connect(jdbcURL, properties);
278294
} catch (SQLException e) {
279295
LOGGER.error(e.getMessage());
280296
}
@@ -286,10 +302,12 @@ protected static Connection getJdbcV2() {
286302
properties.put("user", getUsername());
287303
properties.put("password", getPassword());
288304

289-
ClickHouseNode node = getServer();
290305
Connection jdbcV2 = null;
306+
String jdbcURL = jdbcURLV1(isCloud());
307+
LOGGER.info("JDBC URL: " + jdbcURL);
308+
291309
try {
292-
jdbcV2 = new ClickHouseDriver().connect(String.format("jdbc:clickhouse://%s:%s", node.getHost(), node.getPort()), properties);
310+
jdbcV2 = new ClickHouseDriver().connect(jdbcURL, properties);
293311
} catch (SQLException e) {
294312
LOGGER.error(e.getMessage());
295313
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.clickhouse.benchmark.clients;
22

33
import org.openjdk.jmh.annotations.Benchmark;
4+
import org.openjdk.jmh.annotations.Level;
5+
import org.openjdk.jmh.annotations.TearDown;
46
import org.slf4j.Logger;
57
import org.slf4j.LoggerFactory;
68

@@ -14,6 +16,27 @@
1416

1517
public class JDBCInsert extends BenchmarkBase {
1618
private static final Logger LOGGER = LoggerFactory.getLogger(JDBCInsert.class);
19+
@TearDown(Level.Invocation)
20+
public void verifyRowsInsertedAndCleanup(DataState dataState) {
21+
boolean success;
22+
int count = 0;
23+
do {
24+
success = verifyCount(dataState.tableNameEmpty, dataState.dataSet.getSize());
25+
if (!success) {
26+
LOGGER.warn("Retrying to verify rows inserted");
27+
try {
28+
Thread.sleep(2500);
29+
} catch (InterruptedException e) {
30+
LOGGER.error("Error: ", e);
31+
}
32+
}
33+
} while (!success && count++ < 10);
34+
if (!success) {
35+
LOGGER.error("Failed to verify rows inserted");
36+
throw new RuntimeException("Failed to verify rows inserted");
37+
}
38+
truncateTable(dataState.tableNameEmpty);
39+
}
1740
void insetData(Connection connection, DataState dataState) throws SQLException {
1841
int size = dataState.dataSet.getSchema().getColumns().size();
1942
String names = dataState.dataSet.getSchema().getColumns().stream().map(column -> column.getColumnName()).collect(Collectors.joining(","));

0 commit comments

Comments
 (0)