Skip to content

Balance the selected PR performance tests over the shards by their measured runtimes - #132767

Open
groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:perf-pr-shards-balance-by-runtime
Open

groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:perf-pr-shards-balance-by-runtime

Conversation

@groeneai

@groeneai groeneai commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #131328
Related: #129327

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):

...

Description

PR Performance Comparison (amd_release, master_head, N/6) shards in selected mode are killed at the 7200 s job timeout when the heaviest selected tests land on one shard, and the whole shard reports nothing. Example: amd_release 5/6, 92 min of tests while its five siblings, with the same 642 selected tests, needed 42 to 69 min.

Every query of a selected XML runs, so test costs differ by three orders of magnitude (amd: jit_aggregate_functions ~1240 s, string_sort ~950 s, the median test under 60 s), but the name-sorted selection is split round robin, which ignores the cost.

The selected tests now go through assign_tests, the longest-first balancer of the coverage collection. The weight of each test is its median runtime in the PR runs of the same architecture at its largest recorded number of queries, from 8 days to 1 day before the workflow run started, so every shard and every rerun attempt reads the same rows. Selected-mode shards are not reused from the CI cache (do_not_cache): their tests and weights come from CIDB, outside the job digest. A test without a runtime gets the upper quartile; a test changed since, or absent from, the coverage timings keeps at least that. With no runtime at all, the committed coverage timings are the weights. PR mode also weights shell-query tests (skip_shell_queries=False); the coverage assignment is unchanged. Full mode, master, nightly and Iceberg runs keep round robin.

Validated offline with the real method on recorded CIDB data: on the killed head the heaviest shard goes from 92 to 68 min; over the heads since 2026-11-15 20:00 (out of sample for the weights), heaviest-shard test time p99/max goes from 72.5/76.9 to 55.0/56.8 min (239 amd heads) and from 60.0/74.4 to 46.2/58.6 min (743 arm heads).

🤖 Generated with Claude Code


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

groeneai and others added 2 commits November 18, 2026 19:00
…asured runtimes

In PR selected mode every query of every selected XML runs, so the cost of
a test spans three orders of magnitude (amd: jit_aggregate_functions ~1240 s
with 400 queries, string_sort ~950 s, the median test under 60 s). The
name-sorted selection was split round robin, which ignores that cost: when
the heaviest tests land on one shard it needs 25-50 min more than its
siblings and is killed at the 7200 s job timeout, losing every result of
the shard (amd_release 5/6 of 469ce02: 92 min of tests, siblings 42-69).

Split the selected tests with `assign_tests`, the longest-first balancer the
coverage collection already uses for the same XML files. Weight each test by
`quantileExact(wall_clock_sec)` over the PR runs of the same architecture in
`perf_test_times_v1` that ran all its queries (the rows with the test's
largest `queries`), in the window from 8 days to 1 day before the selection
cutoff. Every shard of a run has the same cutoff and the window is settled,
so all shards compute the same assignment. Each weight carries the identity
recorded in the committed coverage timings, so a test changed since then
keeps the changed-input floor (the upper quartile); a test without a runtime
gets the upper quartile. If the read returns nothing, the committed coverage
timings are the weights. A CIDB failure takes the existing selection
SKIPPED/ERROR paths.

`assign_tests` gains `skip_shell_queries` (default True, as before): coverage
collection cannot run shell queries, PR runs do, so PR mode weights them.
NightlyCoverage's assignment is unchanged (`--show-plan` byte-identical).
Full mode, master, nightly and Iceberg runs keep round robin.

Offline replay with the real method and recorded CIDB data (weights out of
sample): heaviest-shard test minutes, p99/max, heads since 2026-11-15 20:00:
amd 239 heads 72.5/76.9 -> 55.0/56.8, arm 743 heads 60.0/74.4 -> 46.2/58.6;
the killed run 92 -> 68.

Considered: a deadline in `run_tests` (the shard still fails), sampling 10
queries of coverage-selected tests (drops the queries coverage chose), 8 AMD
shards (more machines for an imbalance that is free to fix), the committed
coverage weights alone (instrumented runtimes predict release ones poorly;
the killed run only drops to 84 min).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`shard_tests` anchored its runtime window on `selection_cutoff()`, which on a
rerun attempt is the start of that attempt. Rerunning some shards then read a
shifted window and split the same selection differently from the shards whose
results are kept, so some tests ran on no final shard and others on two
(ClickHouse#125013's 642 tests: 502 of them move for a rerun one hour later).

Anchor the window on `info.workflow_start_time`, which every attempt of the
run keeps. The first attempt sends the same query as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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; 3 findings over 2 rounds) plus my own review (4 findings).

# Sev Finding Verdict Evidence / action
1 ⚠️ The weights window followed the rerun attempt's start, so rerunning some shards split the same selection differently (502 of 642 tests moved for a rerun 1 h later) AGREE, fixed @ 44697eb window anchored on the workflow start time, which every attempt keeps; 0 of 642 tests move now
2 💡 Tests absent from the coverage timings also get the upper-quartile floor; the text said only "changed" AGREE, fixed @ 44697eb README and description wording
3 ❌ A sampled 10-query run can stand in for an all-query runtime DISAGREE amd window: only date_time_short (20 s vs 39 s; the upper quartile is no closer). arm: only tests run by 1 or 2 PRs so far (e.g. avro_decoder), off by one test until its first all-query run, never worse than round robin; the out-of-sample arm replay still drops the heaviest shard from 74.4 to 58.6 min
4 ⚠️ No committed test exercises shard_tests DISAGREE no tests for test infrastructure; offline replay with mutations (round robin, coverage weights, identity floor, shell weighting) recorded
5 💡 "A rerun keeps the placement" holds for an unchanged selected set: a rerun re-reads coverage and earlier failures by design AGREE, noted the weights are attempt-invariant; a different selection is re-split, as with round robin

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

Session id: cron:clickhouse-review-slot-10:20261118-193100

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, offline. Re-slicing the 642 selected tests of the killed run round robin reproduces all 6 real shard lists and the 92.0 min of tests on 5/6 (its job log, to Export system logs).
b Root cause explained? Every query of a selected XML runs, so test costs span three orders of magnitude (jit_aggregate_functions ~1240 s, median < 60 s), while the name-sorted selection was split round robin, which ignores cost.
c Fix matches root cause? Yes. The split now uses assign_tests (longest first) with the all-query PR runtimes of the same architecture. Selection, query policy and shard count are unchanged.
d Test intent preserved / new tests added? No committed test: test-infrastructure change. Validated by replay with the real method on recorded CIDB data, plus four mutations that each redden.
e Both directions demonstrated? Round robin: 92.0 min on the killed shard, amd p99/max 72.5/76.9 over 239 heads. This change: 68.1 min, 55.0/56.8 (arm 743 heads: 60.0/74.4 to 46.2/58.6).
f Fix is general across code paths? The PR selected branch is the only all-query run that is split by name. Full mode samples 10 queries on 8 shards, nightly and Iceberg have their own placements, and the coverage collection already uses this balancer (its assignment is unchanged).
g Fix generalizes across inputs (params/datatypes/wrappers)? 160 partitions checked: subsets of 0, 1, 5, 6, 7, 50, 300 and all tests, on 6 and 8 shards, including shell-query tests, new and changed tests, and an empty CIDB answer. Two hash seeds give identical output.
h Backward compatible? (maintainer-approved exception only) Yes. No setting and no format. The new assign_tests keyword defaults to the old behaviour, so the coverage --show-plan output is byte-identical.
i Invariants and contracts preserved? Each selected XML runs on exactly one shard: every shard of every attempt reads the same inputs (a window closed one day before the workflow run start, which a rerun keeps, quantileExact) and the assignment is deterministic, so a rerun of some shards moves 0 of 642 tests. A CIDB failure takes the existing SKIPPED/ERROR path.

Session id: cron:clickhouse-impl-slot-5:20261118-184501

@clickhouse-gh

clickhouse-gh Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [23facef]

Summary: ✅


AI Review

Summary

The PR balances selected performance tests using historical runtimes while retaining all queries in each selected test. Reviewed all four changed files at 23facef18da3fa70cec557ef4a63b9eede73507f and all prior discussion. The previous cache-assignment finding is addressed by do_not_cache on both normal and empty selected-mode completion paths. Focused verification with actual AMD and ARM runtime rows passed partition completeness, unchanged-selection rerun stability, shell-query weighting, empty-history handling, and timeout propagation. No actionable findings remain.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors manual approve Manual approve required to run CI comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). labels Nov 18, 2026
The tests of a selected-mode shard and their placement on the shards
come from CIDB (the coverage cohort, the previous failures of the PR and,
since the runtime balancing, the PR runtimes of the 8 days to 1 day
before the workflow run started). None of it is part of the job digest,
so a later workflow with the same digest could reuse the success records
of some shards and run the others with a different assignment: the tests
moved off the re-run shards then have no execution at all.

Complete selected-mode shards with `do_not_cache`, the praktika flag for a
verdict that depends on run-time state no digest input captures, as the
unavailable-selection path of the same job already does. Full mode keeps
its cache: round robin over the digested list of tests.

Reuse of these shards across workflows needs an unchanged merge-commit
build digest: in the 14 days to 2026-11-18, 3 of the 939 PR heads with
AMD `master_head, N/6` shards had a cached `amd_release` build, and all three
re-ran every shard, so the cache saved nothing measurable here.

The README and the `shard_tests` comment now say that a rerun keeps
the placement for the same selection only: a rerun attempt advances
the selection cutoff, so the selected set itself can change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

can be tested Allows running workflows for external contributors comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). manual approve Manual approve required to run CI pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant