ClickHouse's native TCP .NET client vs HTTP, on our hardware

On 2026-10-16 ClickHouse shipped an experimental native TCP client inside ClickHouse.Driver. Against ClickHouse Cloud from an m7i.8xlarge, they reported columnar reads in 0.44× the HTTP time and 6 MB vs 1.6 GB allocated for 1M hits rows. We reran a smaller case on our own box — self-hosted ClickHouse 26.9.27.3, .NET 10.0.13, localhost, 500k × 12 columns — and measured what still holds.
Headline on this box: TCP StreamAsync (columns) read those 500k rows in a median 96.7 ms / 1.3 MiB, versus HTTP QueryAsync<Hit> at 225.1 ms / 82.8 MiB — 0.43× the time and about 64× less allocated. Like-for-like POCO (QueryAsync<Hit> on both) was 154.4 ms / 68.5 MiB on TCP, or 0.69× the HTTP time. Columnar inserts of 100k rows were also faster than HTTP InsertBinaryAsync.
This is a performance case study on one noisy VM, not a ranking of every ClickHouse client. It does not cover JWT auth, file-format exports, compression over a WAN, or ADO.NET consumers.
What the TCP client changes on the wire
The HTTP client in ClickHouse.Driver speaks ClickHouse over port 8123 and typically materializes RowBinary (or JSON) into rows / POCOs. The new ClickHouseTcpClient speaks the Native columnar protocol on port 9000. Fixed-width columns stay contiguous; StreamAsync hands you a borrowed Block whose column .Values are spans over the socket buffer.
Illustrative only — not a measured packet capture.
ClickHouse documents three TCP tiers (blog, TCP docs):
| Tier | Read API | Insert API | Cost shape |
|---|---|---|---|
| Columns | StreamAsync (borrowed blocks) |
InsertAsync(columns) |
No per-row allocation for fixed-width columns |
| POCOs | QueryAsync<T> |
InsertRowsAsync<T> |
One object per row |
object[] |
QueryAsync |
row inserts | Boxed cells; highest alloc |
Trade-offs they call out, and that we hit in code: the API is experimental (compiler warning CHTCP0001), there is no DbDataReader / ADO.NET, blocks from StreamAsync are borrowed for one loop iteration, and HTTP still owns JWT, some file formats, and JSON-as-structured-values workflows.
Environment and methodology
| Item | Value |
|---|---|
| Host | 8 vCPU Intel Xeon, 15 GiB RAM, Debian 13, Linux 6.12.94 |
| ClickHouse | 26.9.27.3, single node, default settings |
| Client | .NET 10.0.13 / SDK 10.0.402, ClickHouse.Driver 1.5.0, BenchmarkDotNet 0.15.8 |
| Endpoints | 127.0.0.1:8123 (HTTP) and 127.0.0.1:9000 (native TCP) |
| Compression | Compression=none on the TCP connection string (localhost; avoids mixing codec cost into the protocol comparison) |
| Dataset | MergeTree table, 500,000 rows × 12 columns (UInt64, UInt16, Float64/32, Bool, LowCardinality(String), String, UUID, DateTime, Int32/64), ORDER BY (region, id) |
| Read SQL | SELECT of all 12 columns, full table scan |
| Inserts | Separate 100,000-row batches into a truncated target table |
| Timing | 5 runs per arm; discard the first (cold); report the median of the remaining 4. GC.Collect between runs; allocations via GC.GetTotalAllocatedBytes(precise: true) |
| Checksum | Every read arm must return n=500000 and the same sum(score) |
Their published setup used ClickHouse Cloud 26.4, an AWS m7i.8xlarge client, a real network, and 1M rows of the wide hits table. Ours is co-located on a smaller VM with a narrower schema, so absolute times and absolute allocations are not comparable — only the relative story is.
Download the harness: clickhouse-dotnet-tcp-vs-http-sample.zip.
Acknowledge the experimental warning the same way the docs show:
<PropertyGroup>
<NoWarn>$(NoWarn);CHTCP0001</NoWarn>
</PropertyGroup>
Connecting both clients
using ClickHouse.Driver;
using ClickHouse.Driver.Tcp;
var http = new ClickHouseClient(
"Host=127.0.0.1;Port=8123;Username=default;Database=default");
http.RegisterPocoType<Hit>(); // HTTP needs an explicit registration
await using var tcp = new ClickHouseTcpClient(
"Host=127.0.0.1;Port=9000;Username=default;Database=default;Compression=none");
// TCP builds POCO maps automatically — no RegisterPocoType
HTTP matches POCO property names case-sensitively. Our columns are snake_case, so we annotated the type with [ClickHouseColumn(Name = "...")]. Without that, QueryAsync<Hit> silently left Score at 0 while still yielding 500k empty-looking objects — a mapping bug that would have invalidated the comparison.
TCP maps without regard to case or underscores, which is why the same Hit type worked on both once the HTTP attributes were in place.
Reading: columns win; POCO still helps
const string sql =
"SELECT id, user_id, event_type, score, amount, flag, region, city, " +
"session_id, created_at, payload_a, payload_b FROM bench_tcp_vs_http";
// HTTP baseline — one Hit per row
await foreach (Hit row in http.QueryAsync<Hit>(sql))
sum += row.Score;
// TCP columns — borrowed blocks; Values is a span over the socket buffer
await foreach (Block block in tcp.StreamAsync(sql))
{
n += block.RowCount;
foreach (double s in block.Column<double>("score").Values)
sum += s;
}
// TCP like-for-like POCO
await foreach (Hit row in tcp.QueryAsync<Hit>(sql))
sum += row.Score;
Do not stash a Block (or its column spans) past the end of the await foreach iteration. The TCP docs state the buffers are reused on the next block.
Median of 4 warm runs after discarding the first of 5. Same checksum on every arm.
Allocated bytes per full scan, measured with GC.GetTotalAllocatedBytes.
| Arm | Median time | Allocated | vs HTTP time | vs HTTP alloc |
|---|---|---|---|---|
HTTP QueryAsync<Hit> |
225.1 ms | 82.8 MiB | 1.00× | 1.00× |
TCP StreamAsync columns |
96.7 ms | 1.3 MiB | 0.43× | 0.016× |
TCP QueryAsync<Hit> |
154.4 ms | 68.5 MiB | 0.69× | 0.83× |
TCP QueryAsync object[] |
144.3 ms | 194.4 MiB | 0.64× | 2.35× |
A BenchmarkDotNet pass with [MemoryDiagnoser] on the same read arms (Monitoring job, 1 warmup + 5 iterations) landed in the same neighborhood: HTTP mean 230.0 ms / 82.8 MB, TCP columns 74.6 ms / 1.3 MB (ratio 0.33), TCP POCO 186.6 ms / 68.5 MB. We treat the manual medians as the primary numbers because they share one process, one checksum path, and the insert arms.
How this compares to ClickHouse’s published figures
Claim (their blog, 1M hits, Cloud + m7i.8xlarge) |
On this box (500k × 12 cols, localhost) |
|---|---|
| Columns ≈ 0.44× HTTP time | Columns ≈ 0.43× HTTP POCO time |
| POCO ≈ two thirds of HTTP time | POCO ≈ 0.69× HTTP time |
| Columns allocate 6 MB vs 1.6 GB | Columns allocate 1.3 MiB vs 82.8 MiB |
The time ratio for columns reproduced closely even though absolute times differ. The absolute allocation gap is smaller here because hits is much wider than our 12-column table — HTTP pays per decoded cell. object[] on TCP was faster than HTTP but allocated more than HTTP POCO; that arm is the wrong default for hot paths.
Inserts: columns and POCOs both beat HTTP binary rows
// HTTP — row-oriented binary insert
await http.InsertBinaryAsync(
"bench_insert_target",
["id", "user_id", "score", "region", "payload"],
objRows); // object[][]
// TCP — typed columns, no per-row projection
await tcp.InsertAsync(
"INSERT INTO bench_insert_target (id, user_id, score, region, payload) VALUES",
[
ClickHouseTcpColumn.Create("id", ids),
ClickHouseTcpColumn.Create("user_id", userIds),
ClickHouseTcpColumn.Create("score", scores),
ClickHouseTcpColumn.Create("region", regions),
ClickHouseTcpColumn.Create("payload", payloads),
]);
// TCP — POCO rows
await tcp.InsertRowsAsync(
"INSERT INTO bench_insert_target (id, user_id, score, region, payload) VALUES",
pocoRows);
Median of 4 warm of 5 runs. Target table truncated before each run.
| Arm | Median time | Allocated |
|---|---|---|
HTTP InsertBinaryAsync (object[]) |
131.6 ms | 1.4 MiB |
TCP InsertAsync columns |
75.9 ms | 3.5 MiB |
TCP InsertRowsAsync POCO |
83.3 ms | 5.3 MiB |
TCP columns were 0.58× the HTTP insert time. Allocations were slightly higher on TCP because we built typed arrays up front; the HTTP path reused a prebuilt object[][] and streamed RowBinary. For ingestion that already holds columnar buffers, InsertAsync is the natural fit.
When to stay on HTTP
Keep the HTTP client when you need any of:
- ADO.NET / Dapper / ORMs — TCP has no
DbDataReader(docs). - JWT or HTTP-only auth and tooling that already speaks 8123.
- File-format exports and JSON workflows the TCP client still treats as text.
- A stable API surface —
CHTCP0001means the TCP types may still move.
Prefer TCP StreamAsync + InsertAsync for hot analytical reads and bulk loads inside a .NET service that can own the mapping layer. Prefer TCP QueryAsync<T> when you want POCOs without dropping to spans. Avoid object[] on the hot path unless you are bridging to an API that already demands it.
Takeaways
- Columnar
StreamAsyncis the real step-change. On this box it matched ClickHouse’s published ~0.44× time ratio and cut allocations by ~64× versus HTTP POCOs on a 12-column table. - Like-for-like POCO still wins on TCP (~0.69× HTTP time here), but most of the memory win disappears once you allocate a row object per record.
- Map names explicitly on HTTP. Case-sensitive POCO binding plus
snake_casecolumns produced silent zeros until[ClickHouseColumn]was added; checksum the payload, not just the row count. - Localhost hides the network. Their Cloud +
m7i.8xlargenumbers include a real RTT and a wider schema. Re-run on your topology before you rewrite a service.
Next step: clone the sample zip, point both connection strings at your ClickHouse, and compare StreamAsync to your current HTTP QueryAsync<T> on a table you actually query. If the ratio is flat, check compression, column width, and whether you are accidentally on the object[] tier.
