Skip to content

Commit 6ba434a

Browse files
committed
Merge branch 'main' into jmh_component_benchmarking
2 parents 5851e9b + 6f56c9f commit 6ba434a

File tree

13 files changed

+324
-234
lines changed

13 files changed

+324
-234
lines changed

.gitignore

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

performance/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
<artifactId>testng</artifactId>
4848
<version>${testng.version}</version>
4949
</dependency>
50+
<!-- https://mvnrepository.com/artifact/org.testcontainers/clickhouse -->
51+
<dependency>
52+
<groupId>org.testcontainers</groupId>
53+
<artifactId>clickhouse</artifactId>
54+
<version>${testcontainers.version}</version>
55+
</dependency>
56+
5057

5158
<!-- Performance Test Dependencies -->
5259
<dependency>
@@ -188,7 +195,6 @@
188195
<argument>-classpath</argument>
189196
<classpath />
190197
<argument>com.clickhouse.benchmark.BenchmarkRunner</argument>
191-
<argument>--dataset=file://dataset_100K.csv</argument>
192198
<argument>.*</argument>
193199
</arguments>
194200
</configuration>

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.clickhouse.benchmark.clients.Components;
66
import com.clickhouse.benchmark.clients.InsertClient;
77
import com.clickhouse.benchmark.clients.QueryClient;
8-
import com.clickhouse.benchmark.data.DataSet;
98
import org.openjdk.jmh.annotations.Mode;
109
import org.openjdk.jmh.profile.GCProfiler;
1110
import org.openjdk.jmh.profile.MemPoolProfiler;
@@ -21,6 +20,8 @@
2120
import java.util.Map;
2221
import java.util.concurrent.TimeUnit;
2322

23+
import static com.clickhouse.benchmark.TestEnvironment.DB_NAME;
24+
import static com.clickhouse.benchmark.TestEnvironment.isCloud;
2425

2526

2627
public class BenchmarkRunner {
@@ -29,9 +30,8 @@ public static void main(String[] args) throws Exception {
2930
LOGGER.info("Starting Benchmarks");
3031
Map<String, String> argMap = parseArguments(args);
3132

32-
3333
Options opt = new OptionsBuilder()
34-
.param("datasetSourceName", argMap.getOrDefault("dataset", "simple"))
34+
// .param("datasetSourceName", argMap.getOrDefault("dataset", "simple"))
3535
// .include(QueryClient.class.getSimpleName())
3636
// .include(InsertClient.class.getSimpleName())
3737
.include(Components.class.getSimpleName())
@@ -44,11 +44,11 @@ public static void main(String[] args) throws Exception {
4444
.addProfiler("async", "libPath=/Users/mark.zitnik/Downloads/async-profiler-3.0-macos/lib/libasyncProfiler.dylib;output=flamegraph;dir=profile-results;event=alloc")
4545
.warmupIterations(0)
4646
.warmupTime(TimeValue.seconds(10))
47-
.measurementIterations(3)
47+
.measurementIterations(10)
4848
.jvmArgs("-Xms8g", "-Xmx8g")
4949
.measurementTime(TimeValue.seconds(10))
5050
.resultFormat(ResultFormatType.JSON)
51-
.result("jmh-simple-results.json")
51+
.result(String.format("jmh-results-%s-%s.json", isCloud() ? "cloud" : "local", System.currentTimeMillis()))
5252
.build();
5353

5454
new Runner(opt).run();
@@ -71,15 +71,19 @@ public static Map<String, String> parseArguments(String[] args) {
7171
return argMap;
7272
}
7373

74-
public static String getSelectQuery(DataSet dataSet) {
75-
return "SELECT * FROM `" + BenchmarkBase.DB_NAME + "`.`" + dataSet.getTableName() + "`";
74+
public static String getSelectQuery(String tableName) {
75+
return "SELECT * FROM `" + DB_NAME + "`.`" + tableName + "`";
76+
}
77+
78+
public static String getSelectCountQuery(String tableName) {
79+
return String.format("SELECT COUNT(*) FROM `%s`.`%s`", DB_NAME, tableName);
7680
}
7781

78-
public static String getSelectCountQuery(DataSet dataSet) {
79-
return "SELECT COUNT(*) FROM `" + BenchmarkBase.DB_NAME + "`.`" + dataSet.getTableName() + "`";
82+
public static String getInsertQuery(String tableName) {
83+
return String.format("INSERT INTO `%s`.`%s`", DB_NAME, tableName);
8084
}
8185

82-
public static String getInsertQuery(DataSet dataSet) {
83-
return "INSERT INTO `" + BenchmarkBase.DB_NAME + "`.`" + dataSet.getTableName() + "`";
86+
public static String getSyncQuery(String tableName) {
87+
return String.format("SYSTEM SYNC REPLICA `%s`.`%s`", DB_NAME, tableName);
8488
}
8589
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package com.clickhouse.benchmark;
2+
3+
import com.clickhouse.client.ClickHouseCredentials;
4+
import com.clickhouse.client.ClickHouseNode;
5+
import com.clickhouse.client.ClickHouseProtocol;
6+
import com.clickhouse.client.ClickHouseServerForTest;
7+
import com.clickhouse.client.config.ClickHouseClientOption;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
import org.testcontainers.clickhouse.ClickHouseContainer;
11+
import org.testcontainers.containers.wait.strategy.Wait;
12+
13+
import java.net.InetSocketAddress;
14+
import java.time.Duration;
15+
import java.util.Collections;
16+
17+
import static com.clickhouse.benchmark.clients.BenchmarkBase.runQuery;
18+
import static java.time.temporal.ChronoUnit.SECONDS;
19+
20+
public class TestEnvironment {
21+
private static final Logger LOGGER = LoggerFactory.getLogger(TestEnvironment.class);
22+
public static final String DB_NAME = "jmh_benchmarks_" + System.currentTimeMillis();
23+
private static final String CLICKHOUSE_DOCKER_IMAGE = "clickhouse/clickhouse-server:latest";
24+
private static ClickHouseNode serverNode;
25+
private static ClickHouseContainer container;
26+
27+
28+
//Environment Variables
29+
public static boolean isCloud() {
30+
return System.getenv("CLICKHOUSE_HOST") != null;
31+
}
32+
public static String getHost() {
33+
String host = System.getenv("CLICKHOUSE_HOST");
34+
if (host == null) {
35+
host = container.getHost();
36+
}
37+
38+
return host;
39+
}
40+
public static int getPort() {
41+
String port = System.getenv("CLICKHOUSE_PORT");
42+
if (port == null) {
43+
if (isCloud()) {//Default handling for ClickHouse Cloud
44+
port = "8443";
45+
} else {
46+
port = String.valueOf(container.getMappedPort(8123));
47+
}
48+
}
49+
50+
return Integer.parseInt(port);
51+
}
52+
public static String getPassword() {
53+
String password = System.getenv("CLICKHOUSE_PASSWORD");
54+
if (password == null) {
55+
if (isCloud()) {
56+
password = System.getenv("CLICKHOUSE_PASSWORD");
57+
} else {
58+
password = container.getPassword();
59+
}
60+
}
61+
return password;
62+
}
63+
public static String getUsername() {
64+
String username = System.getenv("CLICKHOUSE_USERNAME");
65+
if (username == null) {
66+
if (isCloud()) {
67+
username = "default";
68+
} else {
69+
username = container.getUsername();
70+
}
71+
}
72+
return username;
73+
}
74+
public static ClickHouseNode getServer() {
75+
return serverNode;
76+
}
77+
78+
79+
//Initialization and Teardown methods
80+
public static void setupEnvironment() {
81+
LOGGER.info("Initializing ClickHouse test environment...");
82+
83+
if (isCloud()) {
84+
LOGGER.info("Using ClickHouse Cloud");
85+
container = null;
86+
} else {
87+
LOGGER.info("Using ClickHouse Docker container");
88+
container = new ClickHouseContainer(CLICKHOUSE_DOCKER_IMAGE)
89+
.withPassword("testing_password")
90+
.withEnv("CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT", "1")
91+
.withExposedPorts(8123, 8443)
92+
.waitingFor(Wait.forHttp("/ping").forPort(8123).forStatusCode(200).withStartupTimeout(Duration.of(600, SECONDS)));
93+
container.start();
94+
}
95+
96+
serverNode = ClickHouseNode.builder(ClickHouseNode.builder().build())
97+
.address(ClickHouseProtocol.HTTP, new InetSocketAddress(getHost(), getPort()))
98+
.credentials(ClickHouseCredentials.fromUserAndPassword(getUsername(), getPassword()))
99+
.options(Collections.singletonMap(ClickHouseClientOption.SSL.getKey(), isCloud() ? "true" : "false"))
100+
.database(DB_NAME)
101+
.build();
102+
103+
createDatabase();
104+
}
105+
106+
public static void cleanupEnvironment() {
107+
if (isCloud()) {
108+
dropDatabase();
109+
}
110+
111+
if (container != null && container.isRunning()) {
112+
container.stop();
113+
container = null;
114+
}
115+
}
116+
117+
public static void createDatabase() {
118+
LOGGER.info("Creating database: {}", DB_NAME);
119+
runQuery(String.format("CREATE DATABASE IF NOT EXISTS %s", DB_NAME), false);
120+
}
121+
122+
public static void dropDatabase() {
123+
LOGGER.info("Dropping database: {}", DB_NAME);
124+
runQuery(String.format("DROP DATABASE IF EXISTS %s", DB_NAME));
125+
}
126+
}

0 commit comments

Comments
 (0)