Skip to content

Commit 19b7347

Browse files
authored
Merge pull request #2231 from ClickHouse/mixed-workload
Mixed workloads tests
2 parents b2aae91 + 30879c0 commit 19b7347

File tree

3 files changed

+144
-2
lines changed

3 files changed

+144
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import com.clickhouse.benchmark.clients.Compression;
55
import com.clickhouse.benchmark.clients.Deserializers;
66
import com.clickhouse.benchmark.clients.InsertClient;
7+
import com.clickhouse.benchmark.clients.MixedWorkload;
78
import com.clickhouse.benchmark.clients.QueryClient;
89
import com.clickhouse.benchmark.clients.Serializers;
910
import org.openjdk.jmh.annotations.Mode;
11+
import org.openjdk.jmh.annotations.Threads;
1012
import org.openjdk.jmh.profile.GCProfiler;
1113
import org.openjdk.jmh.profile.MemPoolProfiler;
1214
import org.openjdk.jmh.results.format.ResultFormatType;
@@ -37,10 +39,10 @@ public static void main(String[] args) throws Exception {
3739
.include(Compression.class.getSimpleName())
3840
.include(Serializers.class.getSimpleName())
3941
.include(Deserializers.class.getSimpleName())
42+
.include(MixedWorkload.class.getSimpleName())
4043
.forks(1) // must be a fork. No fork only for debugging
4144
.mode(Mode.SampleTime)
4245
.timeUnit(TimeUnit.MILLISECONDS)
43-
.threads(1)
4446
.addProfiler(GCProfiler.class)
4547
.addProfiler(MemPoolProfiler.class)
4648
.warmupIterations(3)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public class BenchmarkBase {
5555
public void setUpIteration() {
5656
clientV1 = getClientV1();
5757
clientV2 = getClientV2();
58-
5958
}
6059

6160
@TearDown(Level.Iteration)
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
package com.clickhouse.benchmark.clients;
2+
3+
import com.clickhouse.benchmark.BenchmarkRunner;
4+
import com.clickhouse.client.ClickHouseClient;
5+
import com.clickhouse.client.ClickHouseResponse;
6+
import com.clickhouse.client.api.Client;
7+
import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
8+
import com.clickhouse.client.api.insert.InsertResponse;
9+
import com.clickhouse.client.api.insert.InsertSettings;
10+
import com.clickhouse.client.api.query.QueryResponse;
11+
import com.clickhouse.client.config.ClickHouseClientOption;
12+
import com.clickhouse.data.ClickHouseFormat;
13+
import com.clickhouse.data.ClickHouseRecord;
14+
import org.openjdk.jmh.annotations.Benchmark;
15+
import org.openjdk.jmh.annotations.Group;
16+
import org.openjdk.jmh.annotations.Level;
17+
import org.openjdk.jmh.annotations.Scope;
18+
import org.openjdk.jmh.annotations.Setup;
19+
import org.openjdk.jmh.annotations.State;
20+
import org.openjdk.jmh.annotations.TearDown;
21+
import org.openjdk.jmh.annotations.Threads;
22+
import org.openjdk.jmh.infra.Blackhole;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
26+
import static com.clickhouse.benchmark.TestEnvironment.getServer;
27+
28+
@Threads(2)
29+
@State(Scope.Benchmark)
30+
public class MixedWorkload extends BenchmarkBase {
31+
private static final Logger LOGGER = LoggerFactory.getLogger(MixedWorkload.class);
32+
33+
private ClickHouseClient clientV1Shared;
34+
private Client clientV2Shared;
35+
@Setup(Level.Trial)
36+
public void setUpIteration() {
37+
clientV1Shared = getClientV1();
38+
clientV2Shared = getClientV2();
39+
}
40+
41+
@TearDown(Level.Trial)
42+
public void tearDownIteration() {
43+
if (clientV1Shared != null) {
44+
clientV1Shared.close();
45+
clientV1Shared = null;
46+
}
47+
if (clientV2Shared != null) {
48+
clientV2Shared.close();
49+
clientV2Shared = null;
50+
}
51+
}
52+
53+
@TearDown(Level.Iteration)
54+
public void teardownIteration(DataState dataState) {
55+
truncateTable(dataState.tableNameEmpty);
56+
}
57+
58+
// @State(Scope.Thread)
59+
// public static class MixedWorkloadState {
60+
//
61+
// }
62+
63+
@Benchmark
64+
@Group("mixed_v1")
65+
public void insertV1(DataState dataState) {
66+
try {
67+
ClickHouseFormat format = dataState.dataSet.getFormat();
68+
try (ClickHouseResponse response = clientV1Shared.read(getServer())
69+
.write()
70+
.option(ClickHouseClientOption.ASYNC, false)
71+
.format(format)
72+
.query(BenchmarkRunner.getInsertQuery(dataState.tableNameEmpty))
73+
.data(out -> {
74+
for (byte[] bytes: dataState.dataSet.getBytesList(format)) {
75+
out.write(bytes);
76+
}
77+
}).executeAndWait()) {
78+
response.getSummary();
79+
}
80+
} catch (Exception e) {
81+
LOGGER.error("Error: ", e);
82+
}
83+
}
84+
85+
@Benchmark
86+
@Group("mixed_v1")
87+
public void queryV1(DataState dataState, Blackhole blackhole) {
88+
try {
89+
try (ClickHouseResponse response = clientV1Shared.read(getServer())
90+
.query(BenchmarkRunner.getSelectQuery(dataState.tableNameFilled))
91+
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
92+
.option(ClickHouseClientOption.ASYNC, false)
93+
.executeAndWait()) {
94+
for (ClickHouseRecord record: response.records()) {//Compiler optimization avoidance
95+
for (int i = 0; i < dataState.dataSet.getSchema().getColumns().size(); i++) {
96+
blackhole.consume(record.getValue(i).asObject());
97+
}
98+
}
99+
}
100+
} catch (Exception e) {
101+
LOGGER.error("Error: ", e);
102+
}
103+
}
104+
105+
106+
107+
@Benchmark
108+
@Group("mixed_v2")
109+
public void insertV2(DataState dataState) {
110+
try {
111+
ClickHouseFormat format = dataState.dataSet.getFormat();
112+
try (InsertResponse response = clientV2Shared.insert(dataState.tableNameEmpty, out -> {
113+
for (byte[] bytes: dataState.dataSet.getBytesList(format)) {
114+
out.write(bytes);
115+
}
116+
out.close();
117+
}, format, new InsertSettings()).get()) {
118+
response.getWrittenRows();
119+
}
120+
} catch (Exception e) {
121+
LOGGER.error("Error: ", e);
122+
}
123+
}
124+
125+
@Benchmark
126+
@Group("mixed_v2")
127+
public void queryV2(DataState dataState, Blackhole blackhole) {
128+
try {
129+
try(QueryResponse response = clientV2Shared.query(BenchmarkRunner.getSelectQuery(dataState.tableNameFilled)).get()) {
130+
ClickHouseBinaryFormatReader reader = clientV2Shared.newBinaryFormatReader(response);
131+
while (reader.next() != null) {//Compiler optimization avoidance
132+
for (int i = 1; i <= dataState.dataSet.getSchema().getColumns().size(); i++) {
133+
blackhole.consume(reader.readValue(1));
134+
}
135+
}
136+
}
137+
} catch (Exception e) {
138+
LOGGER.error("Error: ", e);
139+
}
140+
}
141+
}

0 commit comments

Comments
 (0)