Skip to content

Commit 764f024

Browse files
authored
Merge pull request #1769 from ClickHouse/adding-performance-tests
Adding performance tests between V1 and V2
2 parents 4fefbb9 + 86f011c commit 764f024

File tree

10 files changed

+597
-52
lines changed

10 files changed

+597
-52
lines changed

clickhouse-client/src/test/java/com/clickhouse/client/ClientIntegrationTest.java

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -882,12 +882,14 @@ public void testQueryWithNoResult() throws ExecutionException, InterruptedExcept
882882

883883
@Test(groups = { "integration" })
884884
public void testQuery() {
885+
testQuery(10000);
886+
}
887+
public void testQuery(int totalRecords) {
885888
ClickHouseNode server = getServer();
886889

887890
try (ClickHouseClient client = getClient()) {
888891
// "select * from system.data_type_families"
889-
int limit = 10000;
890-
String sql = "select number, toString(number) from system.numbers limit " + limit;
892+
String sql = "select number, toString(number) from system.numbers limit " + totalRecords;
891893

892894
try (ClickHouseResponse response = newRequest(client, server)
893895
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
@@ -909,20 +911,8 @@ public void testQuery() {
909911
}
910912
Assert.assertTrue(response.getInputStream().isClosed(),
911913
"Input stream should have been closed since there's no data");
912-
// int counter = 0;
913-
// for (ClickHouseValue value : response.values()) {
914-
// Assert.assertEquals(value.asString(), String.valueOf(index));
915-
// index += counter++ % 2;
916-
// }
917-
Assert.assertEquals(index, limit);
918-
// Thread.sleep(30000);
919-
/*
920-
* while (response.hasError()) { int index = 0; for (ClickHouseColumn c :
921-
* columns) { // RawValue v = response.getRawValue(index++); // String v =
922-
* response.getValue(index++, String.class) }
923-
*
924-
* } byte[] bytes = in.readAllBytes(); String str = new String(bytes);
925-
*/
914+
915+
Assert.assertEquals(index, totalRecords);
926916
} catch (Exception e) {
927917
Assert.fail("Query failed", e);
928918
}
@@ -1992,6 +1982,33 @@ public void testInsertWithCustomFormat() throws ClickHouseException {
19921982
}
19931983
}
19941984

1985+
@Test(groups = { "integration" })
1986+
public void testInsertRawDataSimple() throws Exception {
1987+
testInsertRawDataSimple(1000);
1988+
}
1989+
public void testInsertRawDataSimple(int numberOfRecords) throws Exception {
1990+
String tableName = "test_insert_raw_data_simple";
1991+
ClickHouseNode server = getServer();
1992+
sendAndWait(server, "DROP TABLE IF EXISTS " + tableName,
1993+
"CREATE TABLE IF NOT EXISTS "+ tableName + " (i Int16, f String) engine=MergeTree ORDER BY i");
1994+
try (ClickHouseClient client = getClient()) {
1995+
ClickHouseRequest.Mutation request = client.read(server).write().table(tableName).format(ClickHouseFormat.JSONEachRow);
1996+
ClickHouseConfig config = request.getConfig();
1997+
CompletableFuture<ClickHouseResponse> future;
1998+
try (ClickHousePipedOutputStream stream = ClickHouseDataStreamFactory.getInstance().createPipedOutputStream(config)) {
1999+
// start the worker thread which transfer data from the input into ClickHouse
2000+
future = request.data(stream.getInputStream()).execute();
2001+
for (int i = 0; i < numberOfRecords; i++) {
2002+
BinaryStreamUtils.writeBytes(stream, String.format("{\"i\": %s, \"\": \"JSON\"}", i).getBytes(StandardCharsets.UTF_8));
2003+
}
2004+
}
2005+
2006+
ClickHouseResponseSummary summary = future.get().getSummary();
2007+
Assert.assertEquals(summary.getWrittenRows(), numberOfRecords);
2008+
}
2009+
}
2010+
2011+
19952012
@Test(groups = { "integration" })
19962013
public void testInsertWithInputFunction() throws ClickHouseException {
19972014
ClickHouseNode server = getServer();

clickhouse-http-client/pom.xml

Lines changed: 103 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
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

66
<parent>
@@ -110,15 +110,10 @@
110110
<version>2.35.2</version>
111111
<scope>test</scope>
112112
</dependency>
113-
114113
</dependencies>
115114

116115
<build>
117116
<plugins>
118-
<plugin>
119-
<groupId>org.apache.maven.plugins</groupId>
120-
<artifactId>maven-compiler-plugin</artifactId>
121-
</plugin>
122117
<plugin>
123118
<groupId>org.apache.maven.plugins</groupId>
124119
<artifactId>maven-shade-plugin</artifactId>
@@ -150,7 +145,7 @@
150145
</relocations>
151146
<transformers>
152147
<transformer
153-
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
148+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
154149
<manifestEntries>
155150
<Automatic-Module-Name>com.clickhouse.client.http</Automatic-Module-Name>
156151
</manifestEntries>
@@ -183,4 +178,104 @@
183178
</plugin>
184179
</plugins>
185180
</build>
181+
182+
183+
<profiles>
184+
<profile>
185+
<id>performance-testing</id>
186+
<activation><activeByDefault>false</activeByDefault></activation>
187+
<dependencies>
188+
<dependency>
189+
<groupId>org.openjdk.jmh</groupId>
190+
<artifactId>jmh-core</artifactId>
191+
<version>${jmh.version}</version>
192+
</dependency>
193+
<dependency>
194+
<groupId>org.openjdk.jmh</groupId>
195+
<artifactId>jmh-generator-annprocess</artifactId>
196+
<version>${jmh.version}</version>
197+
</dependency>
198+
</dependencies>
199+
<build>
200+
<plugins>
201+
<plugin>
202+
<groupId>org.apache.maven.plugins</groupId>
203+
<artifactId>maven-compiler-plugin</artifactId>
204+
<configuration>
205+
<annotationProcessorPaths>
206+
<path>
207+
<groupId>org.openjdk.jmh</groupId>
208+
<artifactId>jmh-generator-annprocess</artifactId>
209+
<version>${jmh.version}</version>
210+
</path>
211+
</annotationProcessorPaths>
212+
<release>8</release>
213+
</configuration>
214+
</plugin>
215+
<plugin>
216+
<groupId>org.apache.maven.plugins</groupId>
217+
<artifactId>maven-shade-plugin</artifactId>
218+
<executions>
219+
<execution>
220+
<phase>package</phase>
221+
<goals>
222+
<goal>shade</goal>
223+
</goals>
224+
<configuration>
225+
<finalName>benchmarks</finalName>
226+
<transformers>
227+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
228+
<mainClass>org.openjdk.jmh.Main</mainClass>
229+
</transformer>
230+
</transformers>
231+
</configuration>
232+
</execution>
233+
</executions>
234+
</plugin>
235+
<plugin>
236+
<groupId>org.codehaus.mojo</groupId>
237+
<artifactId>exec-maven-plugin</artifactId>
238+
<executions>
239+
<execution>
240+
<id>run-benchmarks</id>
241+
<phase>integration-test</phase>
242+
<goals>
243+
<goal>exec</goal>
244+
</goals>
245+
<configuration>
246+
<classpathScope>test</classpathScope>
247+
<executable>java</executable>
248+
<arguments>
249+
<argument>-classpath</argument>
250+
<classpath />
251+
<argument>org.openjdk.jmh.Main</argument>
252+
<argument>.*</argument>
253+
</arguments>
254+
</configuration>
255+
</execution>
256+
</executions>
257+
</plugin>
258+
<plugin>
259+
<groupId>org.codehaus.mojo</groupId>
260+
<artifactId>build-helper-maven-plugin</artifactId>
261+
<version>3.6.0</version>
262+
<executions>
263+
<execution>
264+
<id>add-test-source</id>
265+
<phase>generate-test-sources</phase>
266+
<goals>
267+
<goal>add-test-source</goal>
268+
</goals>
269+
<configuration>
270+
<sources>
271+
<source>src/test/perf</source>
272+
</sources>
273+
</configuration>
274+
</execution>
275+
</executions>
276+
</plugin>
277+
</plugins>
278+
</build>
279+
</profile>
280+
</profiles>
186281
</project>

clickhouse-http-client/src/test/java/com/clickhouse/client/http/ClickHouseHttpClientTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ public void testPing() {
217217
.nodeSelector(ClickHouseNodeSelector.of(ClickHouseProtocol.HTTP)).build()) {
218218
Assert.assertTrue(client.ping(getServer(), 3000));
219219
}
220+
}
220221

222+
@Test(groups = "integration")
223+
public void testPingFailure() {
221224
try (ClickHouseClient client = ClickHouseClient.builder().options(getClientOptions())
222225
.nodeSelector(ClickHouseNodeSelector.of(ClickHouseProtocol.HTTP)).build()) {
223226
ClickHouseNodes nodes = ClickHouseNodes.of("http://notthere," + getServer().getBaseUri());
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.clickhouse.client;
2+
3+
import com.clickhouse.client.http.ApacheHttpConnectionImplTest;
4+
import org.openjdk.jmh.annotations.*;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
import java.util.concurrent.TimeUnit;
9+
10+
@BenchmarkMode(Mode.SampleTime)
11+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
12+
@State(Scope.Benchmark)
13+
@Fork(1)
14+
@Threads(1)
15+
public class ClientBenchmark {
16+
private static final Logger LOGGER = LoggerFactory.getLogger(ClientBenchmark.class);
17+
private static final int SMALL_SIZE = 1000;
18+
private static final int MEDIUM_SIZE = 1000000;
19+
private static final int LARGE_SIZE = 10000000;
20+
21+
@Setup
22+
public void setup() {
23+
BaseIntegrationTest.setupClickHouseContainer();
24+
}
25+
26+
@TearDown
27+
public void tearDown() {
28+
BaseIntegrationTest.teardownClickHouseContainer();
29+
}
30+
31+
public static void main(String[] args) throws Exception {
32+
org.openjdk.jmh.Main.main(args);
33+
}
34+
35+
// Add benchmark methods here
36+
@Benchmark
37+
public void pingBenchmark() {
38+
LOGGER.info("(V1) Ping benchmark");
39+
ApacheHttpConnectionImplTest apacheHttpConnectionImplTest = new ApacheHttpConnectionImplTest();
40+
apacheHttpConnectionImplTest.testPing();
41+
}
42+
43+
@Benchmark
44+
public void queryBenchmarkSmall() throws Exception {
45+
LOGGER.info("(V1) Query benchmark");
46+
ApacheHttpConnectionImplTest apacheHttpConnectionImplTest = new ApacheHttpConnectionImplTest();
47+
apacheHttpConnectionImplTest.testQuery(SMALL_SIZE);
48+
}
49+
50+
@Benchmark
51+
public void queryBenchmarkMedium() throws Exception {
52+
LOGGER.info("(V1) Query benchmark");
53+
ApacheHttpConnectionImplTest apacheHttpConnectionImplTest = new ApacheHttpConnectionImplTest();
54+
apacheHttpConnectionImplTest.testQuery(MEDIUM_SIZE);
55+
}
56+
57+
@Benchmark
58+
public void queryBenchmarkLarge() throws Exception {
59+
LOGGER.info("(V1) Query benchmark");
60+
ApacheHttpConnectionImplTest apacheHttpConnectionImplTest = new ApacheHttpConnectionImplTest();
61+
apacheHttpConnectionImplTest.testQuery(LARGE_SIZE);
62+
}
63+
64+
@Benchmark
65+
public void insertRawDataBenchmarkSmall() throws Exception {
66+
LOGGER.info("(V1) Insert raw data benchmark");
67+
ApacheHttpConnectionImplTest apacheHttpConnectionImplTest = new ApacheHttpConnectionImplTest();
68+
apacheHttpConnectionImplTest.testInsertRawDataSimple(SMALL_SIZE);
69+
}
70+
71+
@Benchmark
72+
public void insertRawDataBenchmarkMedium() throws Exception {
73+
LOGGER.info("(V1) Insert raw data benchmark");
74+
ApacheHttpConnectionImplTest apacheHttpConnectionImplTest = new ApacheHttpConnectionImplTest();
75+
apacheHttpConnectionImplTest.testInsertRawDataSimple(MEDIUM_SIZE);
76+
}
77+
78+
@Benchmark
79+
public void insertRawDataBenchmarkLarge() throws Exception {
80+
LOGGER.info("(V1) Insert raw data benchmark");
81+
ApacheHttpConnectionImplTest apacheHttpConnectionImplTest = new ApacheHttpConnectionImplTest();
82+
apacheHttpConnectionImplTest.testInsertRawDataSimple(LARGE_SIZE);
83+
}
84+
}

0 commit comments

Comments
 (0)