Skip to content

Perf CI: rebuild the hits datasets with constant granularity, so both servers read the same layout - #122459

Merged
egor-click merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/perf-rebuild-const-granularity
Oct 15, 2026
Merged

egor-click merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/perf-rebuild-const-granularity

Conversation

@groeneai

@groeneai groeneai commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #117972
Related: #121456
Related: #110009

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 required: CI-only change.

Description

Performance Comparison goes red on order_by_read_in_order #1 with no regression: PR 117972, arm 2/6 (+18%), PR 119090, arm 4/6 (+50.9%, after #121847), and it is flagged slower on master too (amd 4/6 @ d43d6067).

Since #110009 each server rebuilds the hits datasets itself: a 16-thread INSERT ... SELECT, then OPTIMIZE FINAL. The INSERT splits the rows into parts nondeterministically, and the vertical merge with variable adaptive granularity makes each merged granule follow the input parts, so the two servers end up with different granule boundaries. Query #1 reads in reverse order, i.e. only the last granule, whose size differs between the servers: 510 vs 6041 rows read in the first job, 958 vs 7977 in the second. The layout lasts for the whole job, so every run and the confirmation rerun see the same difference. Over 30 days, 3487 of the 3491 arm runs with a difference above 15% read different rows on the two sides.

rebuild_table now sets use_const_adaptive_granularity = 1 before the INSERT, so both servers write 8192-row granules (the table's index_granularity), and resets it after OPTIMIZE FINAL, so CREATE TABLE ... AS clones (the insert benchmark in trivial_insert_select_from_files) keep the default. The parts are still written by each server's own binary; only the number of rows per granule is pinned. The double-check-perf-tests mirror gets the same two statements and CI's fail-closed OPTIMIZE FINAL, which it was missing, so --populate rebuilds exactly like CI.

Validated with the harness function itself on two local servers (official master build, the CI datasets): before the change every rebuild pair differed, after it every pair is identical.

Local validation
before (L / R) after (L / R)
hits_10m_single, last granule, 3 pairs 6550 / 7685, 7011 / 6833, 84 / 2816 rows 5760 / 5760 in all 3
hits_100m_single, query #1 rows read, 2 pairs 7977 / 993, 2977 / 6515 256 / 256 in both
Populate time (10m + hits_v1 / 100m) 30-32 s / 173-180 s 31-32 s / 175-185 s

After the rebuild, neither the table nor a CREATE TABLE ... AS clone carries the setting (a clone taken before the reset does), and the reset does not rewrite the part. The text_index.xml fill queries still work on the rebuilt table.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.2496-master (included in 26.10 and later)

groeneai and others added 2 commits September 26, 2026 17:58
Since ClickHouse#110009 each perf server rebuilds hits_10m_single, hits_100m_single
and datasets.hits_v1 -> test.hits itself: a 16-thread INSERT ... SELECT,
then OPTIMIZE FINAL. The INSERT splits the rows into parts
nondeterministically, and the vertical merge with variable adaptive
granularity (blocks_are_granules_size in MergeTask) makes every merged
granule follow the input parts' granules, so the left and right servers
get different granule boundaries. order_by_read_in_order ClickHouse#1 reads in
reverse order, only the last granule, whose size is the remainder of that
layout: 510 vs 6041 rows on PR 117972 arm 2/6 (+18%), 958 vs 7977 on
PR 119090 arm 4/6 (+50.9%). The layout lasts for the whole job, so the
difference is perfectly separated and reproducible, and it reds shards.

With use_const_adaptive_granularity the merged part's rows per granule is
one constant computed from its total rows and bytes, capped at
index_granularity. hits rows are 553-713 bytes, far below 10 MiB / 8192,
so both servers get 8192-row granules. The setting only affects parts
written while it is set, so it is reset after OPTIMIZE FINAL: the part
keeps its granules, and CREATE TABLE ... AS clones
(trivial_insert_select_from_files measures an INSERT into one) keep the
default insert path.

The double-check-perf-tests mirror of rebuild_table gets the same two
statements, so --populate keeps matching CI.

Validated on two local servers with the official master build and the CI
datasets, driving the harness function itself: before, every rebuild pair
differed (hits_100m_single query ClickHouse#1 read 7977 vs 993 rows); after, all
pairs are identical (256 rows).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
OPTIMIZE FINAL waits for in-flight merges only for the table's
lock_acquire_timeout_for_background_operations (120 s by default), and
without optimize_throw_if_noop a timed-out wait is a no-op that still
exits 0. The mirror's rebuild_table then reset
use_const_adaptive_granularity on a table that still had several parts,
so the merges after it wrote variable granules again and the two sides
could diverge. The mirror now sends CI's statements: the 600 s merge-lock
budget after CREATE, and OPTIMIZE FINAL with optimize_throw_if_noop = 1,
optimize_skip_merged_partitions = 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 26, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding; bounded: 1 full pass + 1 fix round + 1 delta recheck).

# Sev Finding Verdict Evidence / action
1 ⚠️ The double-check-perf-tests mirror ran a bare OPTIMIZE FINAL. Behind a merge longer than 120 s that is a silent no-op, and the new reset then lets later merges write variable granules again (double_check_perf.py rebuild_table) AGREE, fixed @ 2c7ef6c The mirror now sends CI's statements: the 600 s merge-lock budget and OPTIMIZE ... FINAL SETTINGS optimize_throw_if_noop = 1, optimize_skip_merged_partitions = 1. The delta recheck found nothing new.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-10:20260926-185600

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The unmodified rebuild_table on two local servers (official master build, CI datasets) gave a different layout and a different query #1 read_rows on the two servers in 3/3 hits_10m_single pairs and 2/2 hits_100m_single pairs (7977 vs 993, 2977 vs 6515 rows).
b Root cause explained? The 16-thread INSERT splits rows nondeterministically, and the vertical OPTIMIZE FINAL merge with variable adaptive granularity keeps each input part's granule boundaries, so each server gets its own last granule, which is all that query #1 reads.
c Fix matches root cause? Yes. Constant granularity during the rebuild removes the per-server layout difference where the harness writes the datasets; no threshold, query or dashboard change.
d Test intent preserved / new tests added? Query #1 is unchanged and now reads the same 256-row granule on both servers. CI harness only; validated by the two-server rig.
e Both directions demonstrated? Before: every pair differs. After: 5 of 5 pairs plus the mirror's pair are identical (hits_10m_single 1222 marks, last granule 5760; hits_100m_single 12209 marks, last granule 256). Same binary and data, only the harness file differs.
f Fix is general across code paths? rebuild_table is the only writer of the three hits datasets, and the double-check-perf-tests mirror gets the same change and CI's fail-closed OPTIMIZE. compare.sh restarts reuse the data and never rebuild.
g Fix generalizes across inputs (params/datatypes/wrappers)? All three rebuilt tables (553 to 713 bytes per row, below the 1280 bytes where the 8192 cap stops applying) and both rebuild shapes (in place and datasets.hits_v1 -> test.hits) were checked.
h Backward compatible? (maintainer-approved exception only) Yes. No setting defaults change. The setting is reset after the merge, so table metadata and CREATE TABLE ... AS clones are unchanged (checked with a positive control). Current reference builds accept it, and a rejection would fail Populate loudly.
i Invariants and contracts preserved? Each table still ends as one merged part written by that server's own binary, and the fail-closed OPTIMIZE and swap order are unchanged (now also in the mirror). Left and right now share granule boundaries.

Session id: cron:clickhouse-impl-slot-41:20260926-165600

@groeneai
groeneai requested review from leshikus and maxknv September 26, 2026 19:23
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 26, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b438922]

Summary: ✅


AI Review

Summary

This PR makes the rebuilt hits datasets use constant granularity on both performance-test servers, resets the table setting after the merge, and aligns the local reproduction helper with CI's merge checks. The reported before/after rebuild results support the determinism fix, but the existing concern about losing default-layout benchmark coverage remains unresolved. Review of PR head b438922ccb6e00c4467f9390073b7bd60154e8ce found no additional inline findings.

Findings

⚠️ Majors

  • ci/jobs/performance_tests.py:2229: Changing every rebuilt hits fixture removes its coverage of default variable granularity. createMergeTreeIndexGranularity selects MergeTreeIndexGranularityConstant while this setting is enabled, and MergeTask stops preserving input granules during vertical merges. The later RESET SETTING leaves those parts intact. Consequently, the large hits workloads no longer exercise variable-granularity behavior, potentially hiding regressions in the default path. Benchmarks that create their own tables retain their defaults, but do not establish equivalent coverage for these workloads. Preserve a representative default-layout workload, or supply focused evidence that the lost regression coverage is adequately replaced. Existing inline finding; no duplicate comment posted.
Tests
  • ⚠️ The reported repeated rebuilds, matching read_rows, setting-reset checks, and text-index smoke check establish the intended fixture change. They do not establish the effect on benchmark sensitivity across the affected workloads. Provide a representative comparison of default and constant layouts and identify the coverage retained for variable granularity.
Missing context / blind spots
  • ⚠️ No local dataset rebuild or performance run was performed. At review time, the refreshed head's Praktika reports contained no performance-query results; the AMD performance checks were skipped. Completed results would close the execution-validation gap, although comparisons using constant layouts on both sides alone would not settle the coverage concern above.
Final Verdict

⚠️ Request changes. Address the existing default-layout coverage concern through retained coverage or focused validation. No new inline findings or thread replies were necessary.

Shell.check(f'{client} --query "ALTER TABLE {target} MODIFY SETTING lock_acquire_timeout_for_background_operations = 600"', strict=True, verbose=True)
# Variable granularity would make the merged part's granules follow how the parallel INSERT split the
# rows, which differs between the two servers; a constant one gives both the same layout.
Shell.check(f'{client} --query "ALTER TABLE {target} MODIFY SETTING use_const_adaptive_granularity = 1"', strict=True, verbose=True)

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.

rebuild_table exists so each side rewrites the hits datasets with its own binary and write-time defaults. Forcing use_const_adaptive_granularity = 1 changes that contract: after the OPTIMIZE, the RESET removes the table setting, but the merged part keeps the constant-row granules, so the bulk of the perf suite now runs on a non-default on-disk layout.

That means regressions in the normal use_const_adaptive_granularity = 0 write path stop being visible on the workload that backs most of these comparisons. The PR description validates order_by_read_in_order #1, but it does not show that reshaping all rebuilt hits tables is acceptable for the rest of the suite. This needs either a deterministic rebuild that preserves the default granularity mode, or evidence from a representative before/after perf report that changing the physical layout of these datasets does not mask unrelated regressions.

@clickhouse-gh clickhouse-gh Bot added the comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). label Sep 26, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 2c7ef6c

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Performance Comparison (arm_release, master_head, 3/6) / generate_random_json #1 The shard's own report calls it slower and the dashboard confirmed_regression: client_time 0.926 -> 1.902 s (+105%). The query reads only generateRandom('x JSON(max_dynamic_paths = 4)', 0, 10, 10), and this PR changes only how the harness rebuilds the hits tables. It is the arm slow mode of this query, which the in-tree report also called slower on 16 other pull requests and on master in the last 7 days #122464 (mine, open)
Mergeable Check, PR rollups, red only because of the row above #122464 (mine, open)

Session id: cron:our-pr-ci-monitor:20260926-223058

@egor-click
egor-click enabled auto-merge October 15, 2026 12:18
@egor-click

Copy link
Copy Markdown
Contributor

@groeneai the rerun didnt work, because there is no binary now, i think it is better to refresh and rerun ci

@groeneai

Copy link
Copy Markdown
Collaborator Author

I merged current master into the branch (b438922, no conflicts, the PR diff is unchanged), and a fresh CI run has started: https://github.com/ClickHouse/ClickHouse/actions/runs/38741247265. Auto-merge is still enabled.

@egor-click
egor-click added this pull request to the merge queue Oct 15, 2026
Merged via the queue into ClickHouse:master with commit dc6e4d1 Oct 15, 2026
178 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai manual approve Manual approve required to run CI 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