Skip to content

Bypass compression for small Native protocol frames - #120191

Open
qoega wants to merge 20 commits into
ClickHouse:masterfrom
qoega:codex/native-small-frame-compression
Open

qoega wants to merge 20 commits into
ClickHouse:masterfrom
qoega:codex/native-small-frame-compression

Conversation

@qoega

@qoega qoega commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Bypass compression for frames below 128 bytes produced by Native connection writers when both peers support revision 54498. The bypass is enabled by default; network_compression_min_bytes=0 restores compression of every frame. Older peers retain their configured codec. Framing, checksums and buffer sizing are unchanged; precompressed asynchronous Distributed queue frames retain their stored codec.

Measurements on 2026-11-10 compared thresholds 0 and 128 on the pooled ZSTD implementation at PR head 6f2ffce8b7af0dcc40160f39fd1dd97982b0ce36 (verified CI merge a2a62d91e9c2a40905c9446ec28bbf9c03e3b2c8). For warmed trivial queries at 64/128 clients, four balanced pairs per case measured throughput +1.48–1.65%, server CPU/query −1.48–1.66%, and client CPU/query −1.91–2.26%. The earlier 1/32-client experiment also found modest CPU savings. Detailed measurements, methodology, and reproduction settings.

There is no supported allocation-saving claim: server allocation traffic was noisy, and client allocation traffic increased slightly. For a compressible 95-byte repeated-string result, total application traffic increased by 57.4 bytes/query (+3.05%). Short-window RSS differences do not establish long-term memory savings. The 128-byte cutoff remains a bounded policy choice, not a demonstrated optimum; 0 remains available when the wire-cost tradeoff is undesirable.

Upstream per-frame compression profiling was incorporated in merge de80da23db9fd89731e990ec79193283e84746a4. The measurements above predate that addition and do not measure the current head. New-head performance validation, broader compressible/incompressible payload coverage, and cutoff comparison remain open.

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Bypass compression by default for frames below 128 bytes produced by Native connection writers with compatible peers. Set network_compression_min_bytes=0 to restore compression of every frame.


Workflow [PR]
Sync PR [sync-upstream/pr/120191]

Use `NONE` below the 128-byte `network_compression_min_bytes` default
when both peers advertise protocol revision 54493. Keep compression
framing, checksums, and frame boundaries, and retain the configured
codec for older peers and larger frames.

Document the mixed-frame contract and cover both sending directions,
compatibility, exact thresholds, logs, chunked transport, and block
continuations in a functional test.

The default follows isolated codec measurements; a matched full-server
ThinLTO comparison remains pending. Publish as a draft for CI validation.
@clickhouse-gh

clickhouse-gh Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0b48565]

Summary: ❌

job_name test_name status info comment
Style check FAIL
settings_changes_history FAIL cidb
Code Review DROPPED
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_asan_ubsan) DROPPED
Build (arm_binary) DROPPED

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements comp-codecs Compression/encoding codecs (LZ4/ZSTD/etc.), archive formats (tar/zip/7z), codec selection and IO... labels Sep 15, 2026
The compatibility proxy lowered both `Hello` revisions to 54492 but
left the query's `ClientInfo` at 54493. Fast test enables
`validate_tcp_client_information`, so the server correctly rejected
the inconsistent revision with `CLIENT_INFO_DOES_NOT_MATCH`.

Forward the client handshake and query prefix while rewriting the
`ClientInfo` revision to match. Keep strict server validation enabled.

Reproduced the original failure and passed all 11 corrected functional
groups and the reference comparison on the same optimized ThinLTO server.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120191&sha=ceef15f1b27a45a39bc92df469c29b9da1cb3a20&name_0=PR&name_1=Fast%20test
Related: ClickHouse#120191
Fast test's server requires `notchunked`, so forcing `chunked` rejected
the connection before the final compression check. Prefer chunking with
`chunked_optional` and assert mixed `NONE`/ZSTD frames after negotiation.

Reproduced the exact CI failure, then passed all 11 groups and reference
checks with strict client-information validation under both mandatory
unchunked and optional-chunked server configurations. Wire captures
confirmed each selected send/receive transport and mixed codec frames.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120191&sha=ce0244451735921260e0a00edd95caa69aef0f8f&name_0=PR&name_1=Fast%20test
Related: ClickHouse#120191
Comment thread src/Client/Connection.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing fcb6c98d5 with master 74bc5daa9 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

82 object files changed (+47.12 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Interpreters/Aggregator.cpp.o 29.36 MiB 29.40 MiB +40.10 KiB (+0.13%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

802 translation units recompiled, 8792 s compile time in total, 802 of them have a recent master baseline.

Job report

@qoega
qoega marked this pull request as ready for review September 16, 2026 15:22
The merged release version is now 26.10. Move the new setting out of the 26.9 history block so `compatibility=26.9` restores the pre-feature behavior, and update the wire test to exercise that boundary.

The exact settings-history CI check failed before the change and passes afterward against the complete PR diff. Shell and embedded Python syntax checks also pass.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120191&sha=893f667805079874480a8d98daeffc0c2fc8b092&name_0=PR&name_1=Style%20check

PR: ClickHouse#120191
Comment thread src/Client/Connection.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 33 queries analysed

This PR sends native-protocol frames smaller than 128 bytes uncompressed, saving at most microseconds of compression per frame on the client/server path. It does not change query execution, aggregation or joins. All five flagged improvements (ClickBench Q18 -11.6%, Q33 -14.7%, Q34 -15.7%; TPC-H Q1 -21.5%, Q7 -25.9%) are downgraded to not_sure: the savings run from tens to hundreds of milliseconds, with seconds less CPU on heavy GROUP BY queries that return about 10 rows. For TPC-H Q1 and Q7, the PR timings fall inside master's recent range and the baseline sits above it, so the gap comes from a slow baseline, not from this change.

clickbench

⚠️ 4 inconclusive

Flagged queries (4 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 18 not_sure 894 790 -11.6% <0.0001 aggregation: The -11.6% comes from a heavy GROUP BY that returns only 10 rows. Skipping compression on frames under 128 bytes saves microseconds here, not 104 ms of query time.
⚠️ 28 not_sure 1064 1009 -5.1% <0.0001 aggregation: The -5.1% is borderline: the two tests disagree and the measurements were noisy. The PR only changes how tiny native-protocol frames are compressed, which this query barely uses.
⚠️ 33 not_sure 1153 983 -14.7% <0.0001 aggregation: The -14.7% comes with about 2.1 s less CPU in a large GROUP BY that returns 10 rows. Bypassing compression for small frames cannot save that much work.
⚠️ 34 not_sure 1164 981 -15.7% <0.0001 aggregation: The -15.7% matches Q33's change in both size and CPU drop. Both queries send tiny results, so per-frame compression cost cannot explain the shift.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

⚠️ 2 inconclusive

Flagged queries (2 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 1 not_sure 65 51 -21.5% <0.0001 The -21.5% (14 ms) puts the PR at 51 ms, inside master's recent 50-64 ms range, while the baseline at 65 ms sits just above it. This query is also noisy on master, so the gap comes from the baseline, not the PR.
⚠️ 7 not_sure 81 60 -25.9% <0.0001 The -25.9% (21 ms) puts the PR at 60 ms, inside master's recent 60-78 ms range, while the baseline at 81 ms sits above it. Skipping compression on small frames cannot explain a 21 ms join-query shift.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: c6558c02-862b-4ca3-af05-9e89e1b20830
  • MIRAI run: f9bf7844-4a5a-4a3a-b20c-70547946eecf
  • PR check IDs:
    • clickbench_352476_1791463600
    • clickbench_352488_1791463600
    • clickbench_352495_1791463600
    • tpch_adapted_1_official_352796_1791463657
    • tpch_adapted_1_official_352893_1791463667
    • tpch_adapted_1_official_352905_1791463666

alexey-milovidov and others added 5 commits September 26, 2026 03:10
…frame-compression

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…frame-compression

Resolve the conflict with the move of the settings changes history into the setting declarations
(ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as
trailing arguments of the `DECLARE` of each setting.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Preserve the `uniq` state revision 54493 added on master. Move the small-frame capability and `DBMS_TCP_PROTOCOL_VERSION` to 54494, update the legacy test proxy to advertise 54493, and retain the specifications at their new documentation paths.

Validated the actual legacy proxy functions with synthetic `Hello` and `ClientInfo` bytes, Bash/Python syntax, and the current CI inline settings-history parser. Full server validation is left to fresh CI.

PR: ClickHouse#120191
Preserve the shared compression output path and master protocol revisions;
move the small-frame capability to 54496 and compatibility history to 26.11.
Clarify that precompressed asynchronous `Distributed` queue replay keeps its
stored codec.

Includes the Azure sequential job split that addresses the 9000-second
timeout seen on this branch.

Related: ClickHouse#123849
PR: ClickHouse#120191
CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120191&sha=c0d9b692de33d123b65dce59bf47ed5b28704ee5&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20azure%2C%20sequential%29
Include `network_compression_min_bytes` in `networkCompressionSettings` so
autocomplete and metadata queries honor explicit zero and custom thresholds.
Add regression coverage for explicit overrides and compatibility-derived
values, including which values are serialized.

Addresses the helper-query propagation finding in the review of
ClickHouse#120191.
@mintlify

mintlify Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 0b48565.

Approve preview

qoega added 5 commits November 4, 2026 22:34
Keep `network_compression_min_bytes` at zero by default until measurements
cover the current pooled `ZSTD` path on warmed persistent connections.
The preserved codec microbenchmarks predate this implementation and do not
justify enabling the bypass for every connection.

Enable the threshold explicitly in functional tests, cover the unchanged
default, and remove the test of the superseded compatibility-derived
threshold. Align the setting history and protocol documentation.

Review: ClickHouse#120191 (comment)
Use a 128-byte threshold by default with `network_compression_min_bytes=0`
retained as the explicit opt-out. Restore the matching compatibility
history, functional assertions and helper-query regression coverage.

Current pooled `ZSTD` performance revalidation remains outstanding; the
earlier allocation measurements are not evidence for the current path.

Related: ClickHouse#120191 (comment)
Preserve master revision 54496 for secondary-insert `ProfileEvents` and
move small-frame compression support to revision 54497. Update both
protocol specs, setting documentation, and the legacy proxy boundary.
Keep the bypass enabled by default at 128 bytes.

Related: ClickHouse#120191
Retain the per-stream state introduced for adaptive compression in
`CompressedWriteBuffer`. Pass that state to the configured codec and
`nullptr` to bypassed `NONE` frames, preserving state between larger
frames. Keep the 128-byte network default and protocol revision 54497.

Related: ClickHouse#120191
Related: ClickHouse#124882
Keep upstream `CompressedWriteBuffer` block/byte counters and compression
timing around both configured-codec and `NONE` frames. Preserve codec state,
the 128-byte default, framing and checksums.

Related: ClickHouse#120191
Review: ClickHouse#120191 (comment)
Retain the previous codec in `CompressedReadBufferBase` when alternating
with `NONE`, so `LZ4` and `LZ4HC` streams keep adaptive decoder history
after small tails. Share selection between header and decompression paths
and retain strict mixed-codec validation.

Add a regression covering repeated 1 MiB frames and 29-byte tails at
thresholds 0 and 128, for buffered and direct reads. A SQL round trip
cannot detect this state loss because decoded values remain correct.

Related: ClickHouse#120191
Review: ClickHouse#120191 (comment)
Preserve the upstream aggregation boundary at revision 54497 and move
`SMALL_FRAME_COMPRESSION` to revision 54498. Update the `Native` spec,
setting documentation, and compatibility proxy together.

Retain the `LZ4` decoder-history fix and the enabled-by-default threshold
of 128 bytes.

Related: ClickHouse#120191

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-codecs Compression/encoding codecs (LZ4/ZSTD/etc.), archive formats (tar/zip/7z), codec selection and IO... pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants