11package com .clickhouse .client ;
22
3+ import com .clickhouse .client .api .Client ;
4+ import com .clickhouse .client .api .enums .Protocol ;
5+ import com .clickhouse .client .api .query .GenericRecord ;
36import com .clickhouse .client .insert .InsertTests ;
47import com .clickhouse .client .query .QueryTests ;
58import org .openjdk .jmh .annotations .*;
69import org .slf4j .Logger ;
710import org .slf4j .LoggerFactory ;
11+ import org .testng .Assert ;
812
913import java .util .concurrent .TimeUnit ;
1014
15+ import static com .clickhouse .client .ClickHouseServerForTest .isCloud ;
16+
1117@ BenchmarkMode (Mode .SampleTime )
1218@ OutputTimeUnit (TimeUnit .MILLISECONDS )
1319@ State (Scope .Benchmark )
@@ -19,19 +25,46 @@ public class ClientBenchmark {
1925 private static final int MEDIUM_SIZE = 1000000 ;
2026 private static final int LARGE_SIZE = 10000000 ;
2127
28+ private Client newClient ;
29+ private Client oldClient ;
30+
31+ public static void main (String [] args ) throws Exception {
32+ org .openjdk .jmh .Main .main (args );
33+ }
34+
2235 @ Setup
2336 public void setup () {
2437 BaseIntegrationTest .setupClickHouseContainer ();
38+
39+ ClickHouseNode node = ClickHouseServerForTest .getClickHouseNode (ClickHouseProtocol .HTTP , isCloud (), ClickHouseNode .builder ().build ());
40+ oldClient = new Client .Builder ()
41+ .addEndpoint (Protocol .HTTP , node .getHost (), node .getPort (), false )
42+ .setUsername ("default" )
43+ .setPassword ("" )
44+ .compressClientRequest (false )
45+ .compressServerResponse (false )
46+ .useHttpCompression (false )
47+ .useNewImplementation (false )
48+ .build ();
49+ newClient = new Client .Builder ()
50+ .addEndpoint (Protocol .HTTP , node .getHost (), node .getPort (), false )
51+ .setUsername ("default" )
52+ .setPassword ("" )
53+ .compressClientRequest (false )
54+ .compressServerResponse (false )
55+ .useHttpCompression (false )
56+ .useNewImplementation (true )
57+ .build ();
2558 }
2659
2760 @ TearDown
2861 public void tearDown () {
62+ oldClient .close ();
63+ newClient .close ();
2964 BaseIntegrationTest .teardownClickHouseContainer ();
3065 }
3166
32- public static void main (String [] args ) throws Exception {
33- org .openjdk .jmh .Main .main (args );
34- }
67+
3568
3669 // Add benchmark methods here
3770 @ Benchmark
@@ -68,6 +101,54 @@ public void queryBenchmarkLarge() throws Exception {
68101 queryTests .tearDown ();
69102 }
70103
104+ @ Threads (4 )
105+ @ Benchmark
106+ public void queryBenchmarkSmallParallelOldImpl () throws Exception {
107+ LOGGER .info ("(V2) Query parallel benchmark" );
108+ GenericRecord record = oldClient .queryAll ("SELECT number FROM system.numbers LIMIT " + SMALL_SIZE ).stream ().findFirst ().get ();
109+ Assert .assertNotNull (record );
110+ }
111+
112+ @ Threads (4 )
113+ @ Benchmark
114+ public void queryBenchmarkMediumParallelOldImpl () throws Exception {
115+ LOGGER .info ("(V2) Query parallel benchmark" );
116+ GenericRecord record = oldClient .queryAll ("SELECT number FROM system.numbers LIMIT " + MEDIUM_SIZE ).stream ().findFirst ().get ();
117+ Assert .assertNotNull (record );
118+ }
119+
120+ @ Threads (4 )
121+ @ Benchmark
122+ public void queryBenchmarkLargeParallelOldImpl () throws Exception {
123+ LOGGER .info ("(V2) Query parallel benchmark" );
124+ GenericRecord record = oldClient .queryAll ("SELECT number FROM system.numbers LIMIT " + LARGE_SIZE ).stream ().findFirst ().get ();
125+ Assert .assertNotNull (record );
126+ }
127+
128+ @ Threads (4 )
129+ @ Benchmark
130+ public void queryBenchmarkSmallParallelNewImpl () throws Exception {
131+ LOGGER .info ("(V2) Query parallel benchmark" );
132+ GenericRecord record = newClient .queryAll ("SELECT number FROM system.numbers LIMIT " + SMALL_SIZE ).stream ().findFirst ().get ();
133+ Assert .assertNotNull (record );
134+ }
135+
136+ @ Threads (4 )
137+ @ Benchmark
138+ public void queryBenchmarkMediumParallelNewImpl () throws Exception {
139+ LOGGER .info ("(V2) Query parallel benchmark" );
140+ GenericRecord record = newClient .queryAll ("SELECT number FROM system.numbers LIMIT " + MEDIUM_SIZE ).stream ().findFirst ().get ();
141+ Assert .assertNotNull (record );
142+ }
143+
144+ @ Threads (4 )
145+ @ Benchmark
146+ public void queryBenchmarkLargeParallelNewImpl () throws Exception {
147+ LOGGER .info ("(V2) Query parallel benchmark" );
148+ GenericRecord record = newClient .queryAll ("SELECT number FROM system.numbers LIMIT " + LARGE_SIZE ).stream ().findFirst ().get ();
149+ Assert .assertNotNull (record );
150+ }
151+
71152 @ Benchmark
72153 public void insertRawDataBenchmarkSmall () throws Exception {
73154 LOGGER .info ("(V2) Insert raw data benchmark" );
0 commit comments