Skip to content

Commit 3190722

Browse files
committed
Fixed to use shared and added Blackhole
1 parent d251174 commit 3190722

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

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

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

3+
import com.clickhouse.benchmark.clients.Compression;
34
import com.clickhouse.benchmark.clients.ConcurrentInsertClient;
45
import com.clickhouse.benchmark.clients.ConcurrentQueryClient;
6+
import com.clickhouse.benchmark.clients.Deserializers;
7+
import com.clickhouse.benchmark.clients.InsertClient;
8+
import com.clickhouse.benchmark.clients.QueryClient;
9+
import com.clickhouse.benchmark.clients.Serializers;
510
import org.openjdk.jmh.annotations.Mode;
611
import org.openjdk.jmh.profile.GCProfiler;
712
import org.openjdk.jmh.profile.MemPoolProfiler;
@@ -28,13 +33,13 @@ public static void main(String[] args) throws Exception {
2833
Map<String, String> argMap = parseArguments(args);
2934

3035
Options opt = new OptionsBuilder()
31-
// .include(QueryClient.class.getSimpleName())
32-
// .include(InsertClient.class.getSimpleName())
36+
.include(QueryClient.class.getSimpleName())
37+
.include(InsertClient.class.getSimpleName())
3338
.include(ConcurrentInsertClient.class.getSimpleName())
3439
.include(ConcurrentQueryClient.class.getSimpleName())
35-
// .include(Compression.class.getSimpleName())
36-
// .include(Serializers.class.getSimpleName())
37-
// .include(Deserializers.class.getSimpleName())
40+
.include(Compression.class.getSimpleName())
41+
.include(Serializers.class.getSimpleName())
42+
.include(Deserializers.class.getSimpleName())
3843
.forks(1) // must be a fork. No fork only for debugging
3944
.mode(Mode.SampleTime)
4045
.timeUnit(TimeUnit.MILLISECONDS)
@@ -43,10 +48,10 @@ public static void main(String[] args) throws Exception {
4348
.warmupIterations(1)
4449
.warmupTime(TimeValue.seconds(5))
4550
.measurementIterations(3)
46-
.jvmArgs("-Xms10g", "-Xmx10g")
51+
.jvmArgs("-Xms8g", "-Xmx8g")
4752
.measurementTime(TimeValue.seconds(isCloud() ? 30 : 5))
4853
.resultFormat(ResultFormatType.JSON)
49-
// .output(String.format("jmh-results-%s-%s.out", isCloud() ? "cloud" : "local", System.currentTimeMillis()))
54+
.output(String.format("jmh-results-%s-%s.out", isCloud() ? "cloud" : "local", System.currentTimeMillis()))
5055
.result(String.format("jmh-results-%s-%s.json", isCloud() ? "cloud" : "local", System.currentTimeMillis()))
5156
.build();
5257

@@ -74,6 +79,10 @@ public static String getSelectQuery(String tableName) {
7479
return "SELECT * FROM `" + DB_NAME + "`.`" + tableName + "`";
7580
}
7681

82+
public static String getSelectQueryWithLimit(String tableName, int limit) {
83+
return "SELECT * FROM `" + DB_NAME + "`.`" + tableName + "` LIMIT " + limit;
84+
}
85+
7786
public static String getSelectCountQuery(String tableName) {
7887
return String.format("SELECT COUNT(*) FROM `%s`.`%s`", DB_NAME, tableName);
7988
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.util.concurrent.atomic.AtomicInteger;
2828

2929
import static com.clickhouse.benchmark.TestEnvironment.getServer;
30-
@Threads(2)
30+
@Threads(3)
3131
@State(Scope.Benchmark)
3232
public class ConcurrentInsertClient extends BenchmarkBase {
3333
private static final Logger LOGGER = LoggerFactory.getLogger(ConcurrentInsertClient.class);
@@ -98,7 +98,7 @@ public void insertV1(DataState dataState, ThreadLocalState threadLocalState) {
9898
String tableName = threadLocalState.createTableName();
9999
try {
100100
ClickHouseFormat format = dataState.dataSet.getFormat();
101-
try (ClickHouseResponse response = getClientV1().read(getServer())
101+
try (ClickHouseResponse response = clientV1Shared.read(getServer())
102102
.write()
103103
.option(ClickHouseClientOption.ASYNC, false)
104104
.format(format)

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.openjdk.jmh.annotations.State;
2626
import org.openjdk.jmh.annotations.TearDown;
2727
import org.openjdk.jmh.annotations.Threads;
28+
import org.openjdk.jmh.infra.Blackhole;
2829
import org.slf4j.Logger;
2930
import org.slf4j.LoggerFactory;
3031

@@ -39,6 +40,7 @@
3940
@State(Scope.Benchmark)
4041
public class ConcurrentQueryClient extends BenchmarkBase {
4142
private static final Logger LOGGER = LoggerFactory.getLogger(ConcurrentQueryClient.class);
43+
private static int LIMIT = 10000;
4244
private ClickHouseClient clientV1Shared;
4345
private Client clientV2Shared;
4446
@Setup(Level.Trial)
@@ -64,16 +66,16 @@ public void teardownIteration(DataState dataState) {
6466
truncateTable(dataState.tableNameEmpty);
6567
}
6668
@Benchmark
67-
public void queryV1(DataState dataState) throws InterruptedException {
69+
public void queryV1(DataState dataState, Blackhole blackhole) {
6870
try {
6971
try (ClickHouseResponse response = clientV1Shared.read(getServer())
70-
.query(BenchmarkRunner.getSelectQuery(dataState.tableNameFilled))
72+
.query(BenchmarkRunner.getSelectQueryWithLimit(dataState.tableNameFilled, LIMIT))
7173
.format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
7274
.option(ClickHouseClientOption.ASYNC, false)
7375
.executeAndWait()) {
7476
for (ClickHouseRecord record: response.records()) {//Compiler optimization avoidance
7577
for (int i = 0; i < dataState.dataSet.getSchema().getColumns().size(); i++) {
76-
isNotNull(record.getValue(i), false);
78+
blackhole.consume(record.getValue(i));
7779
}
7880
}
7981
}
@@ -83,13 +85,13 @@ public void queryV1(DataState dataState) throws InterruptedException {
8385
}
8486

8587
@Benchmark
86-
public void queryV2(DataState dataState) {
88+
public void queryV2(DataState dataState, Blackhole blackhole) {
8789
try {
88-
try(QueryResponse response = clientV2Shared.query(BenchmarkRunner.getSelectQuery(dataState.tableNameFilled)).get()) {
90+
try(QueryResponse response = clientV2Shared.query(BenchmarkRunner.getSelectQueryWithLimit(dataState.tableNameFilled, LIMIT)).get()) {
8991
ClickHouseBinaryFormatReader reader = clientV2Shared.newBinaryFormatReader(response);
9092
while (reader.next() != null) {//Compiler optimization avoidance
9193
for (int i = 1; i <= dataState.dataSet.getSchema().getColumns().size(); i++) {
92-
isNotNull(reader.readValue(1), false);
94+
blackhole.consume(reader.readValue(1));
9395
}
9496
}
9597
}

0 commit comments

Comments
 (0)