Repository navigation
Add PGO and BOLT optimization for ClickHouse binary - #100938
Conversation
Add a dispatch workflow `OptimizeClickHouse` (similar to `OptimizeToolchain`) that collects PGO and BOLT profiles by running the performance test suite against an instrumented ClickHouse build. The pipeline stages per architecture (amd64/aarch64): 1. Build ClickHouse with `-fprofile-generate` (PGO instrumentation) 2. Run performance tests to collect execution profiles 3. Merge profiles into `clickhouse-pgo.profdata` 4. Rebuild with PGO + `--emit-relocs` for BOLT 5. Instrument the binary with `llvm-bolt` 6. Run performance tests again for BOLT layout profiles 7. Merge BOLT profiles and upload both as artifacts The collected profiles integrate into release builds: - `CLICKHOUSE_PROFILES_COMMIT` Dockerfile ARG downloads profiles from S3 - `build_clickhouse.py` auto-detects profiles in `/opt/clickhouse-profiles/` and passes `-DCLICKHOUSE_PGO_PROFILE_PATH` to cmake - After linking, `llvm-bolt` post-processes the binary using BOLT profiles - Both PGO and BOLT are opt-in and best-effort (failures do not break builds) New CMake options in `cmake/profile_optimization.cmake`: - `ENABLE_CLICKHOUSE_PGO_GENERATE` — build with instrumentation - `CLICKHOUSE_PGO_PROFILE_PATH` — path to `.profdata` for optimized build - `ENABLE_CLICKHOUSE_BOLT` — add `--emit-relocs` for BOLT post-processing Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Detect whether `/ClickHouse` resolves to the current working directory to support both Docker and local `--no-docker` runs - Use `ninja clickhouse` instead of `ninja clickhouse-bundle` since the bundle target is empty when `ENABLE_CLICKHOUSE_SELF_EXTRACTING=0` Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
PGO instrumentation embeds counter data into every translation unit, which inflates object file sizes beyond the threshold enforced by CHECK_LARGE_OBJECT_SIZES. This is expected and harmless for profile collection builds. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Add `--param` argument to resume from a specific stage, matching the convention in `build_clickhouse.py` - Add `-DCHECK_LARGE_OBJECT_SIZES=0` to PGO instrumented build since PGO counters inflate translation unit sizes beyond the threshold Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [84c2fbe] Summary: ✅ AI ReviewSummaryThis PR adds optional Missing context / blind spots
Final Verdict
|
…tools
- Switch profile collection job to `clickhouse/binary-builder` Docker image
(was `clickhouse/performance-comparison` which lacks the compiler toolchain
needed to build ClickHouse)
- Install `bolt-${LLVM_VERSION}` package in binary-builder Dockerfile to
provide `llvm-bolt` and `merge-fdata` for BOLT optimization
- Fix `clickhouse-client` calls to use the built binary symlink instead of
system PATH (4 occurrences in `start_server` and `configure_datasets`)
- Use versioned `merge-fdata-${LLVM_VERSION}` consistent with other LLVM
tool references
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The `apt-get update` step in `binary-builder` fails because the kitware GPG key inherited from the `fasttest` base image is stale (key `65ADECD7A7039392` cannot be verified). Re-import the latest key before running `apt-get update`. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…olt` The `binary-builder` image inherits pinned LLVM 21.1.5 packages from the `fasttest` base image. Installing `bolt-21` pulls in LLVM 21.1.8 which conflicts with the older `clang-tools-21` (both provide `clang-scan-deps`). Adding `apt-get upgrade` before the install ensures all inherited LLVM packages are brought to the latest version, preventing the file-overwrite conflict. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100938&sha=c74c07187cd361ae35f21b75e8bf62c8be7a2180&name_0=PR&name_1=Dockers%20Build%20%28amd%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The Docker build fails because `apt-get upgrade` encounters a file conflict between `clang-21` (new version) and `clang-tools-21` (old version) — both packages claim ownership of `/usr/lib/llvm-21/bin/clang-scan-deps` during the partial upgrade. Adding `--force-overwrite` to dpkg options resolves this packaging conflict in the upstream LLVM apt repository. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Address review feedback: after BOLT is applied to `programs/clickhouse`, rebuild the `clickhouse-self-extracting` target so that uploaded artifacts in `programs/self-extracting/clickhouse` contain the BOLT-optimized binary instead of the pre-BOLT version. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
When BOLT instrumentation is skipped (e.g. on aarch64), the code creates an empty `clickhouse-bolt.fdata` marker but the compression was guarded by `size > 0`. This left the job without the expected `.zst` artifact that `ArtifactConfigs` declares. Remove the size check so the `.zst` file is always produced when the uncompressed file exists. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
Address review feedback: if `cmake` with `-DCLICKHOUSE_PGO_PROFILE_PATH` fails (for example because the profile is stale or incompatible with the current sources/toolchain), retry once without the profile. Apply the same fallback to the build stage: if `ninja` fails when `use_pgo` is true, reconfigure without PGO and rebuild. This mirrors the existing BOLT fallback so PGO-profile usage is truly opt-in and non-blocking for release builds. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…-optimization # Conflicts: # ci/defs/defs.py
|
@groeneai, provide a fix for data race: BuzzHouse (amd_tsan) FAIL |
|
@alexey-milovidov — this isn't caused by PR #100938. The same TSan data race in Root cause: Fix already in flight: #104072 (open since 2026-05-05, 13 days awaiting review). Branch
Could you take a look or hand it to a reviewer who can — landing it stops both the master serverfuzz noise and these PR-side hits. Session: cron:clickhouse-ci-task-worker:20260518-013000 |
|
@groeneai, investigate the failure:
This is not caused by this PR (which only changes CI/build files for |
|
@alexey-milovidov — fix-PR opened: #105252 (#105252). Approach: raise Data behind the choice:
The 6144 limit is essentially at the typical working-set mean, so any input that triggers moderate extra allocations during parsing trips the limit. The bump to 8192 is consciously conservative — it stops the chronic pattern (8-15 OOMs/day → ~0-1/month based on history) while still bounding the fuzzer (genuine multi-GB regressions above 8 GB will still surface). The corpus/parser-memory-growth root cause (the other two options from your directive) would be a separate, larger effort and would not address the immediate chronic CI flakiness. Happy to revisit if 8192 itself becomes the chronic boundary. |
|
@alexey-milovidov — fix PR is up: #105252 Bumps CIDB data (30 days):
54/55 observed OOMs (98%) fall under 8192 Mb. The 6144 limit is essentially at the typical working-set mean for this fuzzer, so any input that triggers even moderate extra allocations during parsing trips the limit. Same precedent as merged PR #105134 which bumped CI status: ✅ AI Review APPROVED. |
The `Config Workflow -> Check Workflows` job complained that `.github/workflows/optimize_clickhouse.yml` is outdated relative to the generator. Master switched to `--timestamp` flag (replacing the in-shell Python timestamp prefix and `set -o pipefail` boilerplate); re-running `python3 -m ci.praktika yaml` brings the file in sync. Report: ClickHouse#100938
Restore `.github/workflows/{optimize_clickhouse,retry_infra_failures}.yml`
to the previous remote PR tip's content so the push is not rejected by
GitHub's workflow-scope check. The `Config Workflow -> Check Workflows`
job will surface them as outdated; that is expected and will be fixed in
the next master-merge cycle by an environment that has the `workflow`
scope.
Report: ClickHouse#100938
After merging `origin/master` (~220 commits), the praktika YAML generator emits a different shape for the `run` step (uses `--timestamp` flag instead of piping through a Python timestamper, and drops `set -o pipefail`). Bring `.github/workflows/optimize_clickhouse.yml` in line with what `python3 -m ci.praktika yaml` produces from the current sources, so the `Config Workflow -> Check Workflows` job stops failing on outdated workflows. Report: ClickHouse#100938
Restore `.github/workflows/{optimize_clickhouse,auto_releases}.yml` to the
previous remote PR tip's content so the push is not rejected by GitHub's
workflow-scope check. The `Config Workflow -> Check Workflows` job will
surface them as outdated; that is expected and will be fixed in the next
master-merge cycle by an environment that has the `workflow` scope.
Report: ClickHouse#100938
After merging `origin/master`, the praktika YAML generator emits a different shape for the `run` step (uses `--timestamp` flag instead of piping through a Python timestamper, and drops `set -o pipefail`). Bring `.github/workflows/optimize_clickhouse.yml` in line with what `python3 -m ci.praktika yaml` produces from the current sources, so the `Config Workflow -> Check Workflows` job stops failing on outdated workflows. Report: ClickHouse#100938
Restore `.github/workflows/optimize_clickhouse.yml` to the previous remote PR tip's content so the push is not rejected by GitHub's workflow-scope check. The `Config Workflow -> Check Workflows` job will surface it as outdated; that is expected and will be fixed in the next master-merge cycle by an environment that has the `workflow` scope. Report: ClickHouse#100938
The praktika generator on this branch (post-master-sync) emits the new shape for the `run` step (using `--timestamp` instead of an inline Python timestamping pipeline). Bring `.github/workflows/optimize_clickhouse.yml` in line with `python3 -m praktika yaml` output so the `Config Workflow -> Check Workflows` job stops reporting the file as outdated. Report: ClickHouse#100938 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Restore `.github/workflows/optimize_clickhouse.yml` to the previous remote PR tip's content so the push is not rejected by GitHub's workflow-scope check. The `Config Workflow -> Check Workflows` job will surface it as outdated; that is expected and will be fixed in the next master-merge cycle by an environment that has the `workflow` scope. Report: ClickHouse#100938 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`cmake_cmd_no_pgo` was snapshotted before `-DENABLE_CLICKHOUSE_BOLT=ON` was appended, so the retry path on PGO failure dropped not only the PGO profile flag but also the BOLT build flag. Without BOLT enabled the binary is linked without `--emit-relocs` and the later `llvm-bolt` step silently skips optimization. Apply the BOLT flag first, then snapshot the PGO-free command, so the retry preserves BOLT. Address review on ClickHouse#100938.
Server processes were launched with `subprocess.Popen(..., shell=True)` without `start_new_session=True`. They therefore inherited the job's process group, so `stop_server` calling `Utils.terminate_process_group(proc.pid)` could `killpg` the whole job's process group (or fail with permissions) instead of only the spawned server tree. Pass `start_new_session=True` so each spawned shell becomes the leader of its own process group; `getpgid(proc.pid)` then returns that pgid and `killpg` targets only the server tree. Address review on ClickHouse#100938.
…use-optimization Add PGO and BOLT optimization for ClickHouse binary
…gging Validation run https://github.com/ClickHouse/ClickHouse/actions/runs/27740874354 got much further: the server-readiness hang is gone, the aarch64 job ran the whole PGO phase (67 perf tests, 114 profraw files, merged a 278 MB profile) and reached the BOLT build for the first time. Both jobs then died abruptly mid-operation with no clean error: amd64 ~50 min into PGO collection, aarch64 during the ThinLTO BOLT-build link. There were no `MEMORY_LIMIT_EXCEEDED` messages, so this is runner-level resource exhaustion (untracked memory or disk), not the server's own memory tracker. Mitigations: * Remove the instrumented build tree and raw profraw files once the PGO profile is merged, before the second full build. Previously both complete build trees plus the datasets coexisted on disk during the BOLT build — exactly when aarch64 died. * Drop the 100M-row `hits_100m_single` dataset. The 10M set exercises the same code paths; the 100M set is the heaviest disk+memory consumer during collection (the phase where amd64 died) and querying it on the instrumented binary is the likely trigger. Diagnostics: * Log `df`/`free`/`du` at stage boundaries and every 20 perf tests, so a future resource-exhaustion kill shows unambiguously whether disk or RAM ran out. Run: https://github.com/ClickHouse/ClickHouse/actions/runs/27740874354 Related: #100938 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Validation run https://github.com/ClickHouse/ClickHouse/actions/runs/27772867845 made the diagnosis precise: aarch64 now succeeds end to end (204 perf tests, 114 profraw, merged a 278 MB PGO profile, BOLT instrument best-effort skipped), while amd64 fails — and it fails purely on disk. The `df` logging shows free space on the amd64 runner falling from 69 GB after the build to 7.5 GB by the end of collection; the later BOLT-instrument write then dies with `[Errno 28] No space left on device`, which corrupts a result JSON and fails the whole job (the otherwise best-effort BOLT skip never gets a chance). The space is consumed by tables that perf tests create but never drop: when the per-test `timeout` kills `perf.py`, its `DROP` never runs, so tens of GB of synthetic tables accumulate in the instrumented server's data directory. The amd64 runner has a smaller disk (146 GB vs 194 GB on arm) and runs more tests, so only it runs out. Fixes: * Remove the instrumented server's data directory (along with the build tree and raw profraw) before the BOLT build, reclaiming all the leaked-table space; the BOLT pass starts its own fresh server and only needs the merged profile. * Stop collection once free disk falls below a floor, so collection itself can never run the disk to zero on the smaller runner. BOLT instrumentation currently fails on both architectures (`BOLT-ERROR: cannot find BB containing branch destination`) and is skipped as designed; the PGO profile is produced regardless. Getting BOLT instrumentation itself to work is a separate follow-up. Run: https://github.com/ClickHouse/ClickHouse/actions/runs/27772867845 Related: #100938 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The `OptimizeClickHouse` workflow (`Collect ClickHouse Profiles (PGO, BOLT)`) failed on both architectures. amd64: the PGO-instrumented `clickhouse-server` segfaulted on startup right after `Will remap executable in memory.`. The perf-comparison config `zzz-perf-comparison-tweaks-config.xml` force-enables `remap_executable`, and remapping the `.text` segment of the instrumented, non-self-extracting binary crashes it. Strip the setting from the copied configs before launching the server; the default `false` is what profile collection wants (remapping to huge pages is an irrelevant micro-optimization here). aarch64: the job hit the 8h timeout having run only 44 of 447 perf tests. The instrumented binary is several times slower than a release build, individual tests ran for tens of minutes, and passing `--max-queries 0` for the benchmark files ran *all* of their queries. Profile collection is now strictly time-bounded: * each pass gets a wall-clock budget, clamped at run time to the time actually left in the job (via `collection_budget`) so a slow build cannot push collection past the hard kill, after which nothing is uploaded; * each test runs under a hard `timeout` so one heavy test cannot stall a pass; * `--max-query-seconds` / `--prewarm-max-query-seconds` cap per-query time; * `--runs` is reduced (collection only needs to exercise code paths). Tests skipped once a budget is exhausted are logged, never silently dropped. Failing run: https://github.com/ClickHouse/ClickHouse/actions/runs/26215735471 Workflow: https://github.com/ClickHouse/ClickHouse/actions/workflows/optimize_clickhouse.yml Related: ClickHouse#100938 Related: ClickHouse#105477 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add PGO (Profile-Guided Optimization) and BOLT (Binary Optimization and Layout Tool) post-link optimization for the
clickhousebinary. Profiles are collected from CI workloads and applied as a best-effort step during release builds — both stages fall back to non-optimized output if a profile is stale or incompatible.I don't believe it can improve performance, but I expect it can make performance tests more stable to code layout changes.
Version info
26.5.1.916