Skip to content

Commit c3f7f44

Browse files
committed
moved performance code to an application code instead of test
1 parent 814581b commit c3f7f44

29 files changed

+176
-591
lines changed

performance/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
## DataSetGenerator
44

55
```shell
6-
mvn exec:java -Dscope=test -Dexec.mainClass="com.clickhouse.benchmark.data.ClickHouseDataTypesShort" -input <table_fields.sql> -rows <number_of_rows>
6+
mvn exec:java -Dscope=test -Dexec.mainClass="com.clickhouse.com.clickhouse.benchmark.data.ClickHouseDataTypesShort" -input <table_fields.sql> -rows <number_of_rows>
77
```
88

99

1010
## Performance Test
1111

1212
with custom dataset
1313
```shell
14-
mvn test-compile exec:java -Dexec.classpathScope=test -Dexec.mainClass="com.clickhouse.benchmark.BenchmarkRunner" -Dexec.args="--dataset=file://dataset_1741150759025.csv"
14+
mvn test-compile exec:java -Dexec.classpathScope=test -Dexec.mainClass="com.clickhouse.com.clickhouse.benchmark.BenchmarkRunner" -Dexec.args="--dataset=file://dataset_1741150759025.csv"
1515
```
1616

performance/pom.xml

Lines changed: 52 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,48 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

6-
<parent>
7-
<groupId>com.clickhouse</groupId>
8-
<artifactId>clickhouse-java</artifactId>
9-
<version>${revision}</version>
10-
</parent>
11-
12-
<artifactId>java-performance</artifactId>
6+
<artifactId>jmh-benchmark</artifactId>
7+
<groupId>clickhouse.com</groupId>
8+
<version>0.1-SNAPSHOT</version>
139
<packaging>jar</packaging>
1410

15-
<name>ClickHouse Java Performance Tests</name>
16-
<description>ClickHouse Java Performance Tests</description>
11+
<name>JMH Benchmark for Java Client</name>
12+
<description>JMH Benchmark for Java Client</description>
1713
<url>https://github.com/ClickHouse/clickhouse-java/tree/main/performance</url>
1814

1915
<properties>
2016
<apache.httpclient.version>5.3.1</apache.httpclient.version>
21-
<shade.base>${project.groupId}.shaded</shade.base>
17+
<slf4j.version>2.0.17</slf4j.version>
18+
<ch.jdbc.revision>0.8.2-SNAPSHOT</ch.jdbc.revision>
19+
<jmh.version>1.37</jmh.version>
20+
<testcontainers.version>1.20.6</testcontainers.version>
21+
22+
<antrun-plugin.version>3.1.0</antrun-plugin.version>
23+
<assembly-plugin.version>3.6.0</assembly-plugin.version>
24+
<clean-plugin.version>3.3.1</clean-plugin.version>
25+
<compiler-plugin.version>3.13.0</compiler-plugin.version>
26+
<deploy-plugin.version>3.1.1</deploy-plugin.version>
27+
<enforcer-plugin.version>3.3.0</enforcer-plugin.version>
28+
<exec-plugin.version>3.1.0</exec-plugin.version>
29+
<failsafe-plugin.version>3.1.2</failsafe-plugin.version>
30+
<flatten-plugin.version>1.2.7</flatten-plugin.version>
31+
<git-plugin.version>6.0.0</git-plugin.version>
32+
<gpg-plugin.version>3.1.0</gpg-plugin.version>
33+
<helper-plugin.version>3.4.0</helper-plugin.version>
34+
<jacoco-plugin.version>0.8.12</jacoco-plugin.version>
35+
<jar-plugin.version>3.3.0</jar-plugin.version>
36+
<javadoc-plugin.version>3.5.0</javadoc-plugin.version>
37+
<native-plugin.version>0.9.23</native-plugin.version>
38+
<os-plugin.version>1.7.1</os-plugin.version>
39+
<protobuf-plugin.version>0.6.1</protobuf-plugin.version>
40+
<shade-plugin.version>3.5.0</shade-plugin.version>
41+
<source-plugin.version>3.2.1</source-plugin.version>
42+
<staging-plugin.version>1.6.13</staging-plugin.version>
43+
<surefire-plugin.version>3.2.5</surefire-plugin.version>
44+
<toolchains-plugin.version>3.1.0</toolchains-plugin.version>
45+
<versions-plugin.version>2.16.0</versions-plugin.version>
46+
<resource-plugin.version>3.3.1</resource-plugin.version>
47+
2248
</properties>
2349

2450
<dependencies>
@@ -42,63 +68,37 @@
4268
<artifactId>jmh-generator-annprocess</artifactId>
4369
<version>${jmh.version}</version>
4470
</dependency>
45-
<dependency>
46-
<groupId>org.testng</groupId>
47-
<artifactId>testng</artifactId>
48-
<version>${testng.version}</version>
49-
</dependency>
71+
72+
<!-- Performance Test Dependencies -->
73+
<!-- <dependency>-->
74+
<!-- <groupId>org.testcontainers</groupId>-->
75+
<!-- <artifactId>testcontainers</artifactId>-->
76+
<!-- <version>${testcontainers.version}</version>-->
77+
<!-- <scope>compile</scope>-->
78+
<!-- </dependency>-->
5079
<!-- https://mvnrepository.com/artifact/org.testcontainers/clickhouse -->
5180
<dependency>
5281
<groupId>org.testcontainers</groupId>
5382
<artifactId>clickhouse</artifactId>
5483
<version>${testcontainers.version}</version>
5584
</dependency>
5685

57-
58-
<!-- Performance Test Dependencies -->
59-
<dependency>
60-
<groupId>${project.parent.groupId}</groupId>
61-
<artifactId>clickhouse-client</artifactId>
62-
<version>${revision}</version>
63-
</dependency>
64-
<dependency>
65-
<groupId>${project.parent.groupId}</groupId>
66-
<artifactId>clickhouse-client</artifactId>
67-
<version>${revision}</version>
68-
<type>test-jar</type>
69-
</dependency>
70-
<dependency>
71-
<groupId>org.testcontainers</groupId>
72-
<artifactId>testcontainers</artifactId>
73-
<version>${testcontainers.version}</version>
74-
</dependency>
75-
<dependency>
76-
<groupId>${project.parent.groupId}</groupId>
77-
<artifactId>clickhouse-http-client</artifactId>
78-
<version>${revision}</version>
79-
</dependency>
80-
<dependency>
81-
<groupId>${project.parent.groupId}</groupId>
82-
<artifactId>client-v2</artifactId>
83-
<version>${revision}</version>
84-
</dependency>
86+
<!-- Contains both JDBC drivers and clients -->
8587
<dependency>
86-
<groupId>${project.parent.groupId}</groupId>
88+
<groupId>com.clickhouse</groupId>
8789
<artifactId>clickhouse-jdbc</artifactId>
88-
<version>${revision}</version>
89-
</dependency>
90-
<dependency>
91-
<groupId>${project.parent.groupId}</groupId>
92-
<artifactId>jdbc-v2</artifactId>
93-
<version>${revision}</version>
90+
<version>${ch.jdbc.revision}</version>
91+
<classifier>all</classifier>
9492
</dependency>
93+
9594
</dependencies>
9695

9796
<build>
9897
<plugins>
9998
<plugin>
10099
<groupId>org.apache.maven.plugins</groupId>
101100
<artifactId>maven-compiler-plugin</artifactId>
101+
<version>${compiler-plugin.version}</version>
102102
<configuration>
103103
<annotationProcessorPaths>
104104
<path>
@@ -115,26 +115,6 @@
115115
<release>11</release>
116116
</configuration>
117117
</plugin>
118-
<plugin>
119-
<groupId>org.apache.maven.plugins</groupId>
120-
<artifactId>maven-shade-plugin</artifactId>
121-
<executions>
122-
<execution>
123-
<phase>package</phase>
124-
<goals>
125-
<goal>shade</goal>
126-
</goals>
127-
<configuration>
128-
<finalName>benchmarks</finalName>
129-
<transformers>
130-
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
131-
<mainClass>com.clickhouse.benchmark.BenchmarkRunner</mainClass>
132-
</transformer>
133-
</transformers>
134-
</configuration>
135-
</execution>
136-
</executions>
137-
</plugin>
138118
<plugin>
139119
<groupId>org.codehaus.mojo</groupId>
140120
<artifactId>build-helper-maven-plugin</artifactId>
@@ -164,7 +144,7 @@
164144
</descriptorRefs>
165145
<archive>
166146
<manifest>
167-
<mainClass>com.clickhouse.benchmark.BenchmarkRunner</mainClass>
147+
<mainClass>com.clickhouse.com.clickhouse.benchmark.BenchmarkRunner</mainClass>
168148
</manifest>
169149
</archive>
170150
</configuration>
@@ -184,12 +164,11 @@
184164
<executions>
185165
<execution>
186166
<id>run-benchmarks</id>
187-
<phase>integration-test</phase>
188167
<goals>
189168
<goal>exec</goal>
190169
</goals>
191170
<configuration>
192-
<classpathScope>test</classpathScope>
171+
<classpathScope>runtime</classpathScope>
193172
<executable>java</executable>
194173
<arguments>
195174
<argument>-classpath</argument>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.clickhouse.benchmark;
2+
3+
import com.clickhouse.benchmark.clients.*;
4+
import org.openjdk.jmh.annotations.Mode;
5+
import org.openjdk.jmh.profile.GCProfiler;
6+
import org.openjdk.jmh.profile.MemPoolProfiler;
7+
import org.openjdk.jmh.results.format.ResultFormatType;
8+
import org.openjdk.jmh.runner.Runner;
9+
import org.openjdk.jmh.runner.options.ChainedOptionsBuilder;
10+
import org.openjdk.jmh.runner.options.OptionsBuilder;
11+
import org.openjdk.jmh.runner.options.TimeValue;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
14+
15+
import java.util.concurrent.TimeUnit;
16+
17+
import static com.clickhouse.benchmark.TestEnvironment.isCloud;
18+
19+
20+
public class BenchmarkRunner {
21+
private static final Logger LOGGER = LoggerFactory.getLogger(BenchmarkRunner.class);
22+
23+
public static void main(String[] args) throws Exception {
24+
LOGGER.info("Starting Benchmarks");
25+
int measurementIterations = Integer.getInteger("m", 10);
26+
int measurementTime = Integer.getInteger("t", isCloud() ? 30 : 10);
27+
28+
ChainedOptionsBuilder optBuilder = new OptionsBuilder()
29+
.forks(1) // must be a fork. No fork only for debugging
30+
.mode(Mode.SampleTime)
31+
.timeUnit(TimeUnit.MILLISECONDS)
32+
.addProfiler(GCProfiler.class)
33+
.addProfiler(MemPoolProfiler.class)
34+
.warmupIterations(1)
35+
.warmupTime(TimeValue.seconds(5))
36+
.measurementIterations(measurementIterations)
37+
.jvmArgs("-Xms8g", "-Xmx8g")
38+
.measurementTime(TimeValue.seconds(measurementTime))
39+
.resultFormat(ResultFormatType.JSON)
40+
// .output(String.format("jmh-results-%s-%s.out", isCloud() ? "cloud" : "local", System.currentTimeMillis()))
41+
.result(String.format("jmh-results-%s-%s.json", isCloud() ? "cloud" : "local", System.currentTimeMillis()));
42+
43+
String testMask = System.getProperty("b", "q,i");
44+
String[] testMaskParts = testMask.split(",");
45+
46+
// .include(QueryClient.class.getSimpleName())
47+
// .include(InsertClient.class.getSimpleName())
48+
// .include(ConcurrentInsertClient.class.getSimpleName())
49+
// .include(ConcurrentQueryClient.class.getSimpleName())
50+
// .include(Compression.class.getSimpleName())
51+
// .include(Serializers.class.getSimpleName())
52+
// .include(Deserializers.class.getSimpleName())
53+
// .include(MixedWorkload.class.getSimpleName())
54+
55+
56+
new Runner(optBuilder.build()).run();
57+
}
58+
59+
private enum Benchmarks {
60+
61+
QUERY_CLIENT(QueryClient.class, "q");
62+
63+
private Class<QueryClient> queryClientClass;
64+
private String mask;
65+
66+
Benchmarks(Class<QueryClient> queryClientClass, String mask) {
67+
this.queryClientClass = queryClientClass;
68+
this.mask = mask;
69+
}
70+
71+
String benchmarkName() {
72+
return queryClientClass.getName();
73+
}
74+
75+
String mask() {
76+
return mask;
77+
}
78+
}
79+
}

performance/src/test/com/clickhouse/benchmark/TestEnvironment.java renamed to performance/src/main/java/com/clickhouse/benchmark/TestEnvironment.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.clickhouse.client.ClickHouseCredentials;
44
import com.clickhouse.client.ClickHouseNode;
55
import com.clickhouse.client.ClickHouseProtocol;
6-
import com.clickhouse.client.ClickHouseServerForTest;
76
import com.clickhouse.client.config.ClickHouseClientOption;
87
import org.slf4j.Logger;
98
import org.slf4j.LoggerFactory;

performance/src/test/com/clickhouse/benchmark/clients/BenchmarkBase.java renamed to performance/src/main/java/com/clickhouse/benchmark/clients/BenchmarkBase.java

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,22 @@
11
package com.clickhouse.benchmark.clients;
22

3-
import com.clickhouse.benchmark.BenchmarkRunner;
43
import com.clickhouse.benchmark.data.DataSet;
54
import com.clickhouse.benchmark.data.FileDataSet;
65
import com.clickhouse.benchmark.data.SimpleDataSet;
76
import com.clickhouse.benchmark.data.SyntheticDataSet;
8-
import com.clickhouse.client.ClickHouseClient;
9-
import com.clickhouse.client.ClickHouseClientBuilder;
10-
import com.clickhouse.client.ClickHouseCredentials;
11-
import com.clickhouse.client.ClickHouseNode;
12-
import com.clickhouse.client.ClickHouseNodeSelector;
13-
import com.clickhouse.client.ClickHouseProtocol;
14-
import com.clickhouse.client.ClickHouseResponse;
7+
import com.clickhouse.client.*;
158
import com.clickhouse.client.ClickHouseServerForTest;
169
import com.clickhouse.client.api.Client;
17-
import com.clickhouse.client.api.ConnectionReuseStrategy;
1810
import com.clickhouse.client.api.enums.Protocol;
1911
import com.clickhouse.client.api.insert.InsertResponse;
2012
import com.clickhouse.client.api.query.GenericRecord;
21-
import com.clickhouse.client.config.ClickHouseClientOption;
2213
import com.clickhouse.data.ClickHouseDataProcessor;
2314
import com.clickhouse.data.ClickHouseFormat;
2415
import com.clickhouse.data.ClickHouseOutputStream;
2516
import com.clickhouse.data.ClickHouseRecord;
2617
import com.clickhouse.data.format.ClickHouseRowBinaryProcessor;
2718
import com.clickhouse.jdbc.ClickHouseDriver;
28-
import org.openjdk.jmh.annotations.Level;
29-
import org.openjdk.jmh.annotations.Param;
30-
import org.openjdk.jmh.annotations.Scope;
31-
import org.openjdk.jmh.annotations.Setup;
32-
import org.openjdk.jmh.annotations.State;
33-
import org.openjdk.jmh.annotations.TearDown;
19+
import org.openjdk.jmh.annotations.*;
3420
import org.slf4j.Logger;
3521
import org.slf4j.LoggerFactory;
3622

@@ -45,15 +31,7 @@
4531
import java.util.List;
4632
import java.util.Properties;
4733

48-
import static com.clickhouse.benchmark.BenchmarkRunner.getSelectCountQuery;
49-
import static com.clickhouse.benchmark.BenchmarkRunner.getSyncQuery;
50-
import static com.clickhouse.benchmark.TestEnvironment.DB_NAME;
51-
import static com.clickhouse.benchmark.TestEnvironment.cleanupEnvironment;
52-
import static com.clickhouse.benchmark.TestEnvironment.getPassword;
53-
import static com.clickhouse.benchmark.TestEnvironment.getServer;
54-
import static com.clickhouse.benchmark.TestEnvironment.getUsername;
55-
import static com.clickhouse.benchmark.TestEnvironment.isCloud;
56-
import static com.clickhouse.benchmark.TestEnvironment.setupEnvironment;
34+
import static com.clickhouse.benchmark.TestEnvironment.*;
5735

5836
@State(Scope.Benchmark)
5937
public class BenchmarkBase {
@@ -237,7 +215,7 @@ public static void insertData(String tableName, InputStream dataStream, ClickHou
237215

238216
public static boolean verifyCount(String tableName, long expectedCount) {
239217
syncQuery(tableName);
240-
List<GenericRecord> records = runQuery(BenchmarkRunner.getSelectCountQuery(tableName));
218+
List<GenericRecord> records = runQuery(getSelectCountQuery(tableName));
241219
BigInteger count = records.get(0).getBigInteger(1);
242220
if (count.longValue() != expectedCount) {
243221
LOGGER.error("Expected {} but got {}", expectedCount, count);
@@ -299,7 +277,7 @@ protected static Connection getJdbcV1() {
299277
}
300278
return jdbcV1;
301279
}
302-
280+
303281
protected static Connection getJdbcV2() {
304282
Properties properties = new Properties();
305283
properties.put("user", getUsername());
@@ -324,7 +302,7 @@ public static void loadClickHouseRecords(DataState dataState) {
324302

325303
try (ClickHouseClient clientV1 = getClientV1();
326304
ClickHouseResponse response = clientV1.read(getServer())
327-
.query(BenchmarkRunner.getSelectQuery(dataState.tableNameFilled))
305+
.query(getSelectQuery(dataState.tableNameFilled))
328306
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
329307
.executeAndWait()) {
330308

@@ -345,4 +323,24 @@ public static void loadClickHouseRecords(DataState dataState) {
345323
throw new RuntimeException("Error inserting data", e);
346324
}
347325
}
326+
327+
public static String getSelectQuery(String tableName) {
328+
return "SELECT * FROM `" + DB_NAME + "`.`" + tableName + "`";
329+
}
330+
331+
public static String getSelectQueryWithLimit(String tableName, int limit) {
332+
return "SELECT * FROM `" + DB_NAME + "`.`" + tableName + "` LIMIT " + limit;
333+
}
334+
335+
public static String getSelectCountQuery(String tableName) {
336+
return String.format("SELECT COUNT(*) FROM `%s`.`%s`", DB_NAME, tableName);
337+
}
338+
339+
public static String getInsertQuery(String tableName) {
340+
return String.format("INSERT INTO `%s`.`%s`", DB_NAME, tableName);
341+
}
342+
343+
public static String getSyncQuery(String tableName) {
344+
return String.format("SYSTEM SYNC REPLICA `%s`.`%s`", DB_NAME, tableName);
345+
}
348346
}

0 commit comments

Comments
 (0)