Skip to content

Commit 5046205

Browse files
author
Paultagoras
committed
WIP mixed workloads
1 parent b2aae91 commit 5046205

File tree

3 files changed

+145
-8
lines changed

3 files changed

+145
-8
lines changed

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

Lines changed: 9 additions & 7 deletions
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;
@@ -32,21 +34,21 @@ public static void main(String[] args) throws Exception {
3234
Map<String, String> argMap = parseArguments(args);
3335

3436
Options opt = new OptionsBuilder()
35-
.include(QueryClient.class.getSimpleName())
36-
.include(InsertClient.class.getSimpleName())
37-
.include(Compression.class.getSimpleName())
38-
.include(Serializers.class.getSimpleName())
39-
.include(Deserializers.class.getSimpleName())
37+
// .include(QueryClient.class.getSimpleName())
38+
// .include(InsertClient.class.getSimpleName())
39+
// .include(Compression.class.getSimpleName())
40+
// .include(Serializers.class.getSimpleName())
41+
// .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)
4749
.warmupTime(TimeValue.seconds(10))
4850
.measurementIterations(10)
49-
.jvmArgs("-Xms8g", "-Xmx8g")
51+
// .jvmArgs("-Xms8g", "-Xmx8g")
5052
.measurementTime(TimeValue.seconds(isCloud() ? 30 : 10))
5153
.resultFormat(ResultFormatType.JSON)
5254
// .output(String.format("jmh-results-%s-%s.out", isCloud() ? "cloud" : "local", System.currentTimeMillis()))

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

0 commit comments

Comments
 (0)