Skip to content

Commit 858876c

Browse files
committed
split tests for components
1 parent ad5694e commit 858876c

File tree

5 files changed

+243
-192
lines changed

5 files changed

+243
-192
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.clickhouse.benchmark;
22

33

4-
import com.clickhouse.benchmark.clients.Components;
4+
import com.clickhouse.benchmark.clients.Compression;
5+
import com.clickhouse.benchmark.clients.Deserializers;
56
import com.clickhouse.benchmark.clients.InsertClient;
67
import com.clickhouse.benchmark.clients.QueryClient;
8+
import com.clickhouse.benchmark.clients.Serializers;
79
import org.openjdk.jmh.annotations.Mode;
810
import org.openjdk.jmh.profile.GCProfiler;
911
import org.openjdk.jmh.profile.MemPoolProfiler;
@@ -32,7 +34,9 @@ public static void main(String[] args) throws Exception {
3234
Options opt = new OptionsBuilder()
3335
.include(QueryClient.class.getSimpleName())
3436
.include(InsertClient.class.getSimpleName())
35-
// .include(Components.class.getSimpleName())
37+
.include(Compression.class.getSimpleName())
38+
.include(Serializers.class.getSimpleName())
39+
.include(Deserializers.class.getSimpleName())
3640
.forks(1) // must be a fork. No fork only for debugging
3741
.mode(Mode.SampleTime)
3842
.timeUnit(TimeUnit.MILLISECONDS)

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

Lines changed: 0 additions & 190 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.clickhouse.benchmark.clients;
2+
3+
import com.clickhouse.benchmark.data.DataSet;
4+
import com.clickhouse.client.api.internal.ClickHouseLZ4OutputStream;
5+
import com.clickhouse.data.ClickHouseOutputStream;
6+
import com.clickhouse.data.stream.Lz4OutputStream;
7+
import net.jpountz.lz4.LZ4Factory;
8+
import org.openjdk.jmh.annotations.Benchmark;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
12+
import java.io.ByteArrayOutputStream;
13+
14+
public class Compression extends BenchmarkBase {
15+
private static final Logger LOGGER = LoggerFactory.getLogger(Compression.class);
16+
17+
@Benchmark
18+
public void CompressingOutputStreamV1(DataState dataState) {
19+
DataSet dataSet = dataState.dataSet;
20+
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); ClickHouseOutputStream out =
21+
new Lz4OutputStream(baos, 8196, null)) {
22+
for (byte[] bytes : dataSet.getBytesList(dataSet.getFormat())) {
23+
out.write(bytes);
24+
}
25+
} catch (Exception e) {
26+
LOGGER.error("Error: ", e);
27+
}
28+
}
29+
30+
private static final LZ4Factory factory = LZ4Factory.fastestInstance();
31+
32+
@Benchmark
33+
public void CompressingOutputStreamV2(DataState dataState) {
34+
DataSet dataSet = dataState.dataSet;
35+
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
36+
ClickHouseLZ4OutputStream out = new ClickHouseLZ4OutputStream(baos,
37+
factory.fastCompressor(), 8196)) {
38+
for (byte[] bytes : dataSet.getBytesList(dataSet.getFormat())) {
39+
out.write(bytes);
40+
}
41+
} catch (Exception e) {
42+
LOGGER.error("Error: ", e);
43+
}
44+
}
45+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.clickhouse.benchmark.clients;
2+
3+
import com.clickhouse.client.ClickHouseConfig;
4+
import com.clickhouse.client.api.Client;
5+
import com.clickhouse.client.api.data_formats.RowBinaryWithNamesAndTypesFormatReader;
6+
import com.clickhouse.client.api.data_formats.internal.BinaryStreamReader;
7+
import com.clickhouse.client.api.query.QueryResponse;
8+
import com.clickhouse.client.api.query.QuerySettings;
9+
import com.clickhouse.client.config.ClickHouseClientOption;
10+
import com.clickhouse.data.ClickHouseColumn;
11+
import com.clickhouse.data.ClickHouseDataProcessor;
12+
import com.clickhouse.data.ClickHouseFormat;
13+
import com.clickhouse.data.ClickHouseInputStream;
14+
import com.clickhouse.data.ClickHouseRecord;
15+
import com.clickhouse.data.format.ClickHouseRowBinaryProcessor;
16+
import org.openjdk.jmh.annotations.Benchmark;
17+
import org.openjdk.jmh.annotations.Level;
18+
import org.openjdk.jmh.annotations.Setup;
19+
import org.openjdk.jmh.infra.Blackhole;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
23+
import java.io.ByteArrayInputStream;
24+
import java.io.InputStream;
25+
import java.nio.ByteBuffer;
26+
import java.util.Collections;
27+
import java.util.List;
28+
import java.util.Map;
29+
30+
public class Deserializers extends BenchmarkBase {
31+
private static final Logger LOGGER = LoggerFactory.getLogger(Deserializers.class);
32+
33+
@Setup(Level.Iteration)
34+
public void setUpIteration(DataState dataState) {
35+
super.setUpIteration();
36+
37+
try (Client c = getClientV2(); QueryResponse r = c.query("SELECT * FROM " + dataState.tableNameFilled, new QuerySettings()
38+
.setFormat(ClickHouseFormat.RowBinaryWithNamesAndTypes)).get()){
39+
dataState.datasetAsRowBinaryWithNamesAndTypes = ByteBuffer.wrap(r.getInputStream().readAllBytes());
40+
LOGGER.info("Loaded {} from dataset", dataState.datasetAsRowBinaryWithNamesAndTypes.capacity());
41+
} catch (Exception e ) {
42+
LOGGER.error("Failed to init data for components benchmark", e);
43+
}
44+
}
45+
46+
@Benchmark
47+
public void DeserializerOutputStreamV1(DataState dataState, Blackhole blackhole) {
48+
InputStream input = new ByteArrayInputStream(dataState.datasetAsRowBinaryWithNamesAndTypes.array());
49+
try {
50+
ClickHouseConfig config = new ClickHouseConfig(Collections.singletonMap(ClickHouseClientOption.FORMAT, ClickHouseFormat.RowBinaryWithNamesAndTypes));
51+
ClickHouseDataProcessor p = new ClickHouseRowBinaryProcessor(config,
52+
ClickHouseInputStream.of(input), null, null, Collections.emptyMap());
53+
List<ClickHouseColumn> columns = p.getColumns();
54+
for (ClickHouseRecord record : p.records()) {
55+
for (int i = 0; i < columns.size(); i++) {
56+
blackhole.consume(record.getValue(i).asObject());
57+
}
58+
}
59+
} catch (Exception e) {
60+
LOGGER.error("Error: ", e);
61+
}
62+
}
63+
64+
@Benchmark
65+
public void DeserializerOutputStreamV2(DataState dataState, Blackhole blackhole) {
66+
InputStream input = new ByteArrayInputStream(dataState.datasetAsRowBinaryWithNamesAndTypes.array());
67+
try {
68+
RowBinaryWithNamesAndTypesFormatReader r = new RowBinaryWithNamesAndTypesFormatReader(input,
69+
new QuerySettings()
70+
.setUseTimeZone("UTC")
71+
.setFormat(ClickHouseFormat.RowBinaryWithNamesAndTypes), new BinaryStreamReader.DefaultByteBufferAllocator());
72+
73+
Map<String, Object> row;
74+
while ((row = r.next()) != null) {
75+
for (String column : row.keySet()) {
76+
blackhole.consume(row.get(column));
77+
}
78+
}
79+
80+
} catch (Exception e) {
81+
LOGGER.error("Error: ", e);
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)