Skip to content

Add stateful storage memory profiler - #115675

Merged
qoega merged 10 commits into
ClickHouse:masterfrom
qoega:codex/complex-parser-memory-ci
Sep 7, 2026
Merged

qoega merged 10 commits into
ClickHouse:masterfrom
qoega:codex/complex-parser-memory-ci

Conversation

@qoega

@qoega qoega commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Adds a stateful storage memory profiler alongside the existing AST memory profiler in clickhouse-examples. The new storage_memory_profiler keeps one ClickHouse context alive while it executes ordered SQL scenarios and records a jemalloc heap checkpoint after each scenario.

The separate storage_memory_check.py compares each master/PR checkpoint transition and reuses the existing batch symbolization, stable stack canonicalization, cross-version diff, flamegraph, and HTML report implementation. The scenarios cover table creation, inserts, skip indexes, projections, dictionaries, multiple tables, 1,000 active parts, system metadata, and cleanup.

This implementation PR intentionally does not wire the job into public or private CI configuration. After it merges and the command is present in the published master clickhouse-examples artifact, a short-lived follow-up PR will contain only the CI configuration changes.

Related: #96199

Reference report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/96199/cd143e56627fbed82d9a5295e4733fe6c060efa5/parser_memory_check/parser_memory_report.html

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Not applicable.


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

@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e12888a]

Summary: ✅


AI Review

Summary

This PR adds a stateful storage_memory_profiler example and a matching storage_memory_check.py report job for comparing storage-allocation deltas between master and the PR. The overall direction is reasonable after the earlier fixes, but two review findings still hold in the current head: the first checkpoint is still taken before any query-path warmup, and the shared HTML helper still hardcodes pluralization in a way that breaks the existing parser report.

Missing context / blind spots
  • ⚠️ The new storage check is intentionally not wired into CI yet, so there is still no end-to-end execution evidence for the full master/PR comparison path in this PR.
Findings
⚠️ Majors
  • [src/Examples/storage_memory_profiler.cpp:550] The profiler records start before executing any warmup query. That makes after_01_create_table absorb one-time parser/analyzer/interpreter initialization, so the first delta is no longer attributable only to storage-state allocations. Suggested fix: run and discard a trivial warmup query before the initial flushJemallocThreadCache() / dumpProfile("start"), the same way parser_memory_profiler warms up its measured path.
💡 Nits
  • [ci/jobs/parser_memory_check.py:883] generate_html_report derives the plural label with f"{item_label}s", so the unchanged parser report now renders Querys. Suggested fix: pass an explicit plural form (for example item_label_plural) instead of appending "s".
Final Verdict

Not ready to merge: the two findings above still hold in the current code.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 20, 2026
qoega added 2 commits August 21, 2026 11:39
Use memory-tracked argument storage, keep the multipart-query container explicitly annotated for its fixed API, replace direct standard streams, and forward-declare the context types used by the header.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115675&sha=9072a506700ff5ca3914c44d3c3769d66ec67166&name_0=PR&name_1=Style%20check
@qoega
qoega marked this pull request as draft August 21, 2026 09:56
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e12888a64 with master 26bd12dc6 (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
Binary Master PR Δ
programs/clickhouse-stripped 709.89 MiB 706.85 MiB -3.04 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

3 object files changed (+175.84 KiB total), 1 added.

Object file Master PR Δ
src/Examples/CMakeFiles/clickhouse-examples.dir/storage_memory_profiler.cpp.o new 175.66 KiB +175.66 KiB

737 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

91 translation units recompiled, 207 s compile time in total, 90 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +16.9 s (+9%) in total before that adjustment.

Translation units without a recent master baseline:

  • src/Examples/storage_memory_profiler.cpp: 5.6 s

Job report

qoega added 3 commits August 21, 2026 15:41
Keep a persistent session context across scenario statements, wait for index and projection materialization, and initialize the dedicated MergeTree jemalloc arena before loading storage state.\n\nRelated: ClickHouse#115675
}
fmt::print(stdout, "\n#\ncheckpoint\tallocated_bytes\tdiff_from_start\tdiff_from_prev\n");

/// Initial measurement

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The profiler records the start checkpoint before it has executed any query at all. That means after_01_create_table also pays all the one-time executeQuery/parser/analyzer/interpreter initialization that is triggered by the first statement in the process, so the first scenario is no longer measuring only storage-state allocations.

That breaks the attribution this report is supposed to provide: a PR that changes generic query-framework memory can show up as a "create table" regression here. parser_memory_profiler already had to add an explicit warmup for exactly this reason. Please run and discard a trivial warmup query before taking the initial heap dump so the scenario deltas start from a warmed execution path.

</div>
<div class="summary-item">
<span class="summary-label">Queries</span>
<span class="summary-label">{html_escape(item_label)}s</span>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper still serves parser_memory_check, and with the default item_label="Query" this now renders Querys in the summary header. Appending "s" is not safe once the label became configurable.

Please pass the plural form explicitly (for example a separate item_label_plural parameter) instead of deriving it with f"{item_label}s".

@clickhouse-gh

clickhouse-gh Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

no significant changes detected. K_source=6 K_base=20 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 464463bb-3b47-4674-8b29-4e4c633fd234
  • MIRAI run: 2c0fc5f4-409d-462d-a259-3b1ef878d406
  • PR check IDs:
    • clickbench_304009_1787654800
    • clickbench_304022_1787654800
    • clickbench_304028_1787654800
    • tpch_adapted_1_official_304041_1787654800
    • tpch_adapted_1_official_304066_1787654800
    • tpch_adapted_1_official_304080_1787654800

@qoega
qoega marked this pull request as ready for review September 2, 2026 21:46
@clickhouse-gh clickhouse-gh Bot added the comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). label Sep 4, 2026
@qoega
qoega added this pull request to the merge queue Sep 7, 2026
Merged via the queue into ClickHouse:master with commit aea04d6 Sep 7, 2026
352 of 353 checks passed
@qoega
qoega deleted the codex/complex-parser-memory-ci branch September 7, 2026 19:45
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 7, 2026
pull Bot pushed a commit to SINHASantos/ClickHouse that referenced this pull request Sep 16, 2026
Run the stateful storage scenarios as a separate check while reusing the existing parser memory reporting helpers and the clickhouse-examples artifact.

Related: ClickHouse#115675
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants