Repository navigation
Conversation
…sponse The performance module has a benchmark that decodes the values of a response that is not compressed (Deserializers.DeserializerOutputStreamV2) and one that reads an LZ4 block-compressed response in large pieces without decoding (Compression.queryV2NativeLz4). No benchmark covers the path between them, where the binary reader asks the decompressing stream for 1 to 8 bytes at a time. CompressedRead.decodeV2 reads all rows of a compressed response from memory with client V2: CompressedBlockInputStream and the decoding of each value, without the network and the server. The bytes are the body that the server sends for compress=1; the benchmark gets them one time with a plain HTTP request. The benchmark is a new class. It runs alone by name, has no parameter of its own and does not catch exceptions. No existing class is changed. First numbers on JDK 17 (100,000 rows of 30 columns, 2 runs of 2 forks): 79.5 ms and 147.7 MB for each operation in both runs. In the profile, CompressedBlockInputStream.read has 38% of the CPU samples (HeapByteBuffer.get 10%), the refill of a block 16% (the checksum 9%). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
New class, no existing class is changed. It reads all rows with client V2 and takes each value one time, with the getter of its type (getLong, getDouble, getString and so on), never with readValue. - TypedRead.queryV2 reads the response of a query. - TypedRead.decodeV2 reads the same response from memory, through a stream that has no lock. QueryClient.queryV2 takes each value as an object and QueryClient.queryV2WithTypes takes each value two times; this is the case between them. The getter of each column is chosen one time for a response. The class has getters for the types of the stock dataset and of the time-series dataset. Measured with JMH on JDK 17.0.21, 100,000 rows for each operation, runs A and B of 2 forks each, same jar: - stock dataset (10 Float64, 10 String, 10 Int64 columns): queryV2 115.1 and 116.9 ms, 237.34 MB for each operation; decodeV2 85.8 and 78.9 ms, 237.30 MB. - time-series dataset: queryV2 53.0 and 50.4 ms, 95.42 MB; decodeV2 38.2 and 39.4 ms, 95.39 MB. The allocation is the same in every fork. The time of decodeV2 on the stock dataset is stable inside a fork and differs between forks: 9 forks gave 77.8 to 86.6 ms. Compare its time with 5 forks or more. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…POJOs Two new classes, no existing class is changed. QueryAll reads a whole result into a list with Client.queryAll of client V2, one object for each row: - QueryAll.recordsV2 gets a list of GenericRecord; - QueryAll.pojosV2 gets a list of POJOs, which the client fills through the setters of a registered class. SampleRow is the POJO: a row of a dataset made from sample_dataset.sql (10 Float64, 10 String and 10 Int64 columns). It checks that the table has its columns, and the benchmark proves one time for each iteration that the client sets every property: the client only logs a column that has no setter. Measured with JMH on JDK 17.0.21, heap 2 GiB, runs A and B of 2 forks each, same jar: - 100,000 rows for each operation: recordsV2 401.6 and 394.3 ms, 397.3 MB for each operation; pojosV2 89.7 and 90.2 ms, 88.3 MB (one fork of four: 86.7 MB). For comparison, QueryClient.queryV2 reads the same rows without keeping them in 84 ms and 107.6 MB. - 10 rows for each operation, one run: recordsV2 2.63 ms and 88.2 KB; pojosV2 2.41 ms and 52.1 KB; QueryClient.queryV2 2.41 ms and 52.5 KB. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
New class PojoInsert, no existing benchmark class is changed. PojoInsert.insertV2 inserts a list of POJOs with Client.insert(table, list) of client V2: the client takes each value from the getter of a registered class and writes it in format RowBinary. After each insert the state of the benchmark counts the rows of the table and empties it with its own client, so that no new client is made for each check. SampleRow (the POJO of the QueryAll benchmark) gets a method that makes a row from the values of a dataset row. Measured with JMH on JDK 17.0.21, heap 2 GiB, 2 forks for each run, with InsertClient.insertV2RowBinary in the same call: - 100,000 rows for each insert, runs A and B: insertV2 105.4 and 104.3 ms, 168.05 MB for each insert in every fork; InsertClient.insertV2RowBinary 104.0 and 104.6 ms, 78.44 MB. - 10 rows for each insert, one run: insertV2 56.6 ms and 129.6 KB; InsertClient.insertV2RowBinary 59.8 ms and 2.06 MB, most of which is the new clients of its check after each insert. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
DataSetPojo is a new utility of the benchmarks. It makes the POJO class of a table at run time with ASM: a public class with a field, a getter and a setter for each column, with a primitive type for a number that is not nullable. Tables with the same columns get the same class. It also proves that a read has set every property (the client only logs a column that has no setter). Any benchmark that reads or inserts POJOs can use it. QueryAll.pojosV2 and PojoInsert.insertV2 use it in place of SampleRow, the class that was written by hand for one dataset. SampleRow is removed. Both benchmarks now also run with the time-series dataset. PojoInsert.insertV2 now inserts the rows of the filled table, read one time as POJOs, and proves after the first insert that the table has the content of the filled table. Before, it took the rows that the dataset keeps in memory. Those are the same row as many times as the table has rows: BenchmarkBase.loadClickHouseRecords keeps the one record object that client V1 uses again for each row. That method is not changed here. ASM comes with the client (org.ow2.asm:asm); the build file of the module is not changed. Measured with JMH on JDK 17.0.21, heap 2 GiB, 100,000 rows for each operation, 2 forks for each run, this commit and the commit before it in one session: - QueryAll.pojosV2: 89.3 ms before, 89.8 and 88.4 ms now, 88.27 MB for each operation before and now. The generated class costs nothing. - PojoInsert.insertV2: 106.0 ms before, 143.8 and 142.6 ms now, 168.06 MB before and 168.07 MB now. The client does the same work; the server takes longer for 100,000 different rows than for one row 100,000 times. - time-series dataset, one run: QueryAll.pojosV2 42.2 ms and 71.46 MB; QueryAll.recordsV2 86.4 ms and 182.86 MB; PojoInsert.insertV2 119.3 ms and 63.48 MB. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
CompressedRead read the compressed body of a response with HttpURLConnection. It now reads the response through a client of its own state and compresses it in memory with CompressedBlockOutputStream, the stream that the client uses for its requests, in blocks of 1 MiB as the server sends them. No benchmark of this branch opens a connection of its own. TypedRead.decodeV2 read from a stream class of its own. It now reads from the array stream of ClickHouseInputStream, which has no lock either. The class of the benchmark is removed. Measured with JMH on JDK 17.0.21, heap 2 GiB, 100,000 rows of the stock dataset for each operation, this commit and the commit before it in one session: - CompressedRead.decodeV2: 77.7 ms before (2 forks), 79.5 and 79.6 ms now (runs A and B), 147.67 MB for each operation before and now. The blocks that the client's compressor makes take 2.3% longer to decode than the blocks of the server. - TypedRead.decodeV2: 83.0 ms before (2 forks), 67.8 to 74.0 ms now (9 forks), 237.30 MB before and now. Its time differs between forks as before; compare it with 5 forks or more. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- CompressedRead.decodeV2, TypedRead.queryV2 and TypedRead.decodeV2 made a reader for each operation and did not close it. The reader and its stream are now in a try-with-resources block; for a query the reader is closed before its response, as ResultSetImpl of jdbc-v2 does. - The state of QueryAll and of PojoInsert makes a client for each iteration and closes it in the teardown. When the setup fails after the client was made, the teardown does not run: the setup now closes the client before it gives the exception on. Measured with JMH on JDK 17.0.21, 100,000 rows for each operation, 2 forks, against the commit before: CompressedRead.decodeV2 79.5 -> 79.2 ms and 147.67 MB both; TypedRead.decodeV2 71.3 -> 71.4 ms and 237.30 MB both. The close calls do not change the numbers. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
AI review gate — Human approval in place of AI reviewApproved on the head commit by chernser (write access, not the author), standing in for the AI review:
What to do:
Evaluated at |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit eebf5d4. Configure here.
| } | ||
| if (!hasValue) { | ||
| throw new IllegalStateException("The property of column " + columns[i] + " has no value in " | ||
| + rows.size() + " rows: the client did not call its setter"); |
There was a problem hiding this comment.
Fill check rejects valid empty values
Medium Severity
checkFilled treats null, false, and numeric zero as proof a setter never ran. Those are valid column values, so a nullable, flag, or counter column whose sampled rows are all empty aborts setup even though every setter ran. QueryAll and PojoInsert only sample 100 rows, so zeros at the start of a column fail the same way.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit eebf5d4. Configure here.


Summary
This PR adds JMH benchmarks to the
performancemodule for four paths of client V2 that the suite did not measure: a read through the typed getters,Client.queryAll, the insert of a list of POJOs, and the decode of a compressed response together with its values. Issue #3516 has the reason.The PR adds five files. It does not change an existing class, a build file or a library.
Closes #3516
The benchmarks
TypedRead.queryV2getLong,getDouble,getStringand so on), never withreadValue.TypedRead.decodeV2QueryAll.recordsV2Client.queryAll(sql): the whole result as a list ofGenericRecord.QueryAll.pojosV2Client.queryAll(sql, class, schema): the whole result as a list of POJOs.PojoInsert.insertV2Client.insert(table, list)with a list of POJOs.CompressedRead.decodeV2CompressedBlockInputStreamand the value decoding of the reader.DataSetPojo(incom.clickhouse.benchmark.data) is a utility for POJO benchmarks. It makes the POJO class of a table at run time with ASM: a field, a getter and a setter for each column, with a primitive property for a number that is not nullable. A benchmark registersDataSetPojo.of(schema).type()in the client. No class has to be written for a dataset, and the POJO benchmarks run with each dataset of the suite.How the benchmarks get and check their data
CompressedReadreads the response through a client and compresses it in memory withCompressedBlockOutputStream, the stream that the client uses for its requests, in blocks of 1 MiB. The server sends a compressed response in blocks of 1 MiB too.TypedRead.decodeV2reads from the array stream ofClickHouseInputStream. That stream has no lock. Thereadmethods ofjava.io.ByteArrayInputStreamare synchronized, and the reader calls them for each value.QueryAll.pojosV2proves one time for each iteration that the client set every property of the POJO. The client only logs a column that has no setter.PojoInsert.insertV2counts the rows of the table after each insert. After the first insert it also compares the content of the table with the content of the source table (sum(cityHash64(*))). Then it empties the table. It does this with one client that it keeps for the iteration.How to run them
Build the module as its README says.
BenchmarkRunnerhas no-bflag for the new classes (see "Not in this PR"), so start JMH with the name:Each benchmark also runs alone, for example with
TypedRead\.decodeV2$.Results on
mainLibraries of
mainat1b33bf6d, a dataset of 100,000 rows made fromsample_dataset.sql(10Float64, 10Stringand 10Int64columns), JMH 1.37, JDK 17.0.21, heap 2 GiB, 2 forks, 3 warm-up iterations of 5 s and 5 iterations of 10 s, ClickHouse 26.8 in a container on the same machine. One run. Each run had no error line in the output of the benchmark.TypedRead.queryV2TypedRead.decodeV2QueryAll.recordsV2QueryAll.pojosV2PojoInsert.insertV2CompressedRead.decodeV2For comparison, a short run of existing benchmarks with the same jar gives 107.7 MB for
QueryClient.queryV2and 78.5 MB forInsertClient.insertV2RowBinary.With the time-series dataset of my measurements (
DateTime,DateTime64,Date,UInt64and other columns) the benchmarksTypedRead,QueryAllandPojoInsertrun with no error line too.Two notes for the use of the numbers:
QueryAll.pojosV2had 1.5 MB less.TypedRead.decodeV2is constant in a fork but not between forks: with the libraries of356a218e, 9 forks of one jar gave 67.8 to 74.0 ms. Compare its time with 5 forks or more.What the benchmarks show
Profiles with async-profiler, taken on
356a218e(an older commit ofmain). The allocation of these benchmarks is the same there and on1b33bf6d, but forTypedRead, where #3473 removed 84 MB.Client.queryAll(sql)fills aLinkedHashMapfor each row, andMapBackedRecordcopies it into aHashMap. The two maps are 74% of the allocation. The records stay alive until the call ends, and the pauses of the garbage collector are about 45% of the time. The call takes 4.3 times the time ofqueryAllinto POJOs.TypedRead: the getters of numbers make a box for each value (45.6 MB), andreadValuehas put a box into the record before (46.0 MB).PojoInsert: 55% of the allocation comes from reflection: an empty varargs array for eachMethod.invoke, and a box for each number. 31% of the CPU samples are inChunkedOutputStream.write, because each value is written into the chunked stream of the HTTP client by itself.QueryAll.pojosV2: 15% of the allocation isgetDeclaredConstructor()andnewInstance()for each row.Not in this PR
BenchmarkRunnerand lines in the README for the new classes. They change existing files. I can add them here or in a follow-up, as you prefer.performance/pom.xml.DataSetPojousesorg.objectweb.asm. The module gets it throughclient-v2(org.ow2.asm:asm), so the build works without a change. If you want the dependency declared in the module, it is one entry.PojoInsert:BenchmarkBase.loadClickHouseRecordsadds each record ofresponse.records()of client V1 to a list, and client V1 uses one record object again for each row. SogetRowsOrdered(),getRows()andgetClickHouseRecords()hold the same row as many times as the table has rows. The RowBinary inserts ofInsertClient,ConcurrentInsertClientandMixedWorkload,SerializersandJDBCInsertwrite that one row. Their checks count the rows, so they pass. Measured withPojoInsert.insertV2on356a218e: 106 ms for the one row 100,000 times, 144 ms for 100,000 different rows, with the same allocation.PojoInsertdoes not use these rows: it reads the rows of the filled table one time as POJOs. A fix changes the numbers of the existing insert benchmarks, so I did not put it into this PR.Tests
The change is benchmark code, so there is no unit test. Each benchmark was run with the stock dataset, and
TypedRead,QueryAllandPojoInsertalso with the time-series dataset, with the libraries of356a218eand of1b33bf6d. The branch has no conflict withmain.No entry for the CHANGELOG: the change has no effect on the libraries.
Checklist
🤖 Generated with Claude Code
Note
Low Risk
Additive benchmark-only code in the performance module; no production client or API behavior changes.
Overview
Adds five new files to the
performancemodule—no changes to library code, build configs, or existing benchmarks. Coverage targets client V2 paths that were missing from the suite (closes #3516).DataSetPojogenerates table-shaped POJO classes at runtime with ASM (getters/setters per column, cached by schema) so POJO benchmarks work across datasets without hand-written models;checkFilledvalidates that reads actually populated every property.TypedReadmeasures full-result reads using per-type getters (getLong,getString, etc.) instead ofreadValue, with live query vs in-memory decode variants.QueryAllbenchmarks whole-result materialization asGenericRecordlists vs registered POJO lists.PojoInsertbenchmarksClient.insert(table, list); each invocation is verified (row count, content hash on first run) and the table is truncated for the next iteration.CompressedReadbenchmarks LZ4 block decompression plus row decoding from pre-compressed in-memory payloads (1 MiB blocks), isolating decode cost from network/server.Reviewed by Cursor Bugbot for commit eebf5d4. Bugbot is set up for automated code reviews on this repo. Configure here.