Skip to content

Commit 15eda02

Browse files
authored
Merge pull request #2515 from alekkol/enhance-query-benchmarks
Add benchmarks to reproduce performance regression for query calls
2 parents 865b5e2 + 1f2512a commit 15eda02

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

clickhouse-jdbc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
<path>
239239
<groupId>org.projectlombok</groupId>
240240
<artifactId>lombok</artifactId>
241-
<version>1.18.32</version>
241+
<version>1.18.38</version>
242242
</path>
243243
<path>
244244
<groupId>org.openjdk.jmh</groupId>

client-v2/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
<path>
154154
<groupId>org.projectlombok</groupId>
155155
<artifactId>lombok</artifactId>
156-
<version>1.18.32</version>
156+
<version>1.18.38</version>
157157
</path>
158158
</annotationProcessorPaths>
159159
<release>8</release>

examples/client-v2/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<dependency>
104104
<groupId>org.projectlombok</groupId>
105105
<artifactId>lombok</artifactId>
106-
<version>1.18.32</version>
106+
<version>1.18.38</version>
107107
<scope>provided</scope>
108108
</dependency>
109109

@@ -148,7 +148,7 @@
148148
<path>
149149
<groupId>org.projectlombok</groupId>
150150
<artifactId>lombok</artifactId>
151-
<version>1.18.32</version>
151+
<version>1.18.38</version>
152152
</path>
153153
</annotationProcessorPaths>
154154
</configuration>

performance/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
<path>
108108
<groupId>org.projectlombok</groupId>
109109
<artifactId>lombok</artifactId>
110-
<version>1.18.32</version>
110+
<version>1.18.38</version>
111111
</path>
112112
<path>
113113
<groupId>org.openjdk.jmh</groupId>

performance/src/main/java/com/clickhouse/benchmark/clients/QueryClient.java

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
55
import com.clickhouse.client.api.query.QueryResponse;
66
import com.clickhouse.client.config.ClickHouseClientOption;
7+
import com.clickhouse.data.ClickHouseColumn;
78
import com.clickhouse.data.ClickHouseFormat;
89
import com.clickhouse.data.ClickHouseRecord;
10+
import com.clickhouse.data.ClickHouseValue;
911
import org.openjdk.jmh.annotations.Benchmark;
1012
import org.openjdk.jmh.annotations.Scope;
1113
import org.openjdk.jmh.annotations.State;
1214
import org.openjdk.jmh.infra.Blackhole;
1315
import org.slf4j.Logger;
1416
import org.slf4j.LoggerFactory;
1517

18+
import java.util.List;
19+
1620
import static com.clickhouse.benchmark.TestEnvironment.getServer;
1721

1822
@State(Scope.Benchmark)
@@ -45,12 +49,55 @@ public void queryV2(DataState dataState, Blackhole blackhole) {
4549
ClickHouseBinaryFormatReader reader = clientV2.newBinaryFormatReader(response);
4650
while (reader.next() != null) {//Compiler optimization avoidance
4751
for (int i = 1; i <= dataState.dataSet.getSchema().getColumns().size(); i++) {
48-
blackhole.consume(reader.readValue(1));
52+
blackhole.consume(reader.readValue(i));
4953
}
5054
}
5155
}
5256
} catch (Exception e) {
5357
LOGGER.error("Error: ", e);
5458
}
5559
}
60+
61+
@Benchmark
62+
public void queryV1WithTypes(DataState dataState, Blackhole blackhole) throws Exception {
63+
try (ClickHouseResponse response = clientV1.read(getServer())
64+
.query(BenchmarkBase.getSelectQuery(dataState.tableNameFilled))
65+
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
66+
.option(ClickHouseClientOption.ASYNC, false)
67+
.executeAndWait()) {
68+
List<ClickHouseColumn> columns = dataState.dataSet.getSchema().getColumns();
69+
for (ClickHouseRecord record: response.records()) {//Compiler optimization avoidance
70+
for (int i = 0; i < columns.size(); i++) {
71+
ClickHouseValue value = record.getValue(i);
72+
ClickHouseColumn column = columns.get(i);
73+
switch (column.getDataType()) {
74+
case Int64: blackhole.consume(value.asLong()); break;
75+
case Float64: blackhole.consume(value.asDouble()); break;
76+
case String: blackhole.consume(value.asString()); break;
77+
default: throw new IllegalStateException();
78+
}
79+
}
80+
}
81+
}
82+
}
83+
84+
@Benchmark
85+
public void queryV2WithTypes(DataState dataState, Blackhole blackhole) throws Exception {
86+
try(QueryResponse response = clientV2.query(BenchmarkBase.getSelectQuery(dataState.tableNameFilled)).get()) {
87+
ClickHouseBinaryFormatReader reader = clientV2.newBinaryFormatReader(response);
88+
List<ClickHouseColumn> columns = dataState.dataSet.getSchema().getColumns();
89+
while (reader.next() != null) {//Compiler optimization avoidance
90+
for (int i = 1; i <= columns.size(); i++) {
91+
blackhole.consume(reader.readValue(i));
92+
ClickHouseColumn column = columns.get(i - 1);
93+
switch (column.getDataType()) {
94+
case Int64: blackhole.consume(reader.getLong(i)); break;
95+
case Float64: blackhole.consume(reader.getDouble(i)); break;
96+
case String: blackhole.consume(reader.getString(i)); break;
97+
default: throw new IllegalStateException();
98+
}
99+
}
100+
}
101+
}
102+
}
56103
}

0 commit comments

Comments
 (0)