Skip to content

Clear libfiu's fast-path flag when the last fail point is disabled - #129334

Merged
Algunenano merged 8 commits into
ClickHouse:masterfrom
groeneai:perf-ci-failpoint-tests-last
Nov 10, 2026
Merged

Algunenano merged 8 commits into
ClickHouse:masterfrom
groeneai:perf-ci-failpoint-tests-last

Conversation

@groeneai

@groeneai groeneai commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #100759
Related: ClickHouse/libfiu#8
Related: #119976

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

Since #119976 (2026-10-28) about 17 performance tests run 1.3-24x slower and much noisier, on both servers and both arches: removing_group_by_keys #0 0.13 -> 1.46 s (amd), 0.084 -> 1.29 s (arm); on amd its share of master runs with a difference over 10% went from 0.1% to 28%.

Cause: libfiu's fast-path flag has_any_failpoint_been_registered is set by the first fiu_enable and never cleared. Once an iceberg_suite_*_synthio_* test of #119976 has enabled and disabled s3_slow_response or local_object_storage_slow_response, every fiu_do_on of that server takes libfiu's rwlock and a table lookup until a restart (Aggregator::drainAdaptivePartition checks one per inserted key), and all the tests of a shard share the same two servers.

Change: update contrib/libfiu to ClickHouse/libfiu#8, which keeps the flag equal to "at least one fail point is enabled", recomputed under libfiu's write lock on every enable and disable. The earlier commits of this PR (test order, then removing the synthio tests and adding a style check) are reverted, so the diff is the submodule and the comment of hasAnyFailPointBeenRegistered.

Validation, debug builds, one server, a 3M-key GROUP BY on 8 threads: master takes 0.026 s fresh and 0.73-0.80 s after SYSTEM ENABLE + DISABLE FAILPOINT, for the rest of the process; with this PR 0.021-0.064 s after the same, and it is slow only while a fail point is enabled. Fail points still fire while enabled (also with two enabled and one disabled, and after a re-enable), and SYSTEM DISABLE ALL FAILPOINTS clears the flag.


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

Version info

  • Merged into: 26.11.1.1836-master (included in 26.11 and later)

The first `fiu_enable` sets libfiu's `has_any_failpoint_been_registered`,
which is never reset, so every later `fiu_do_on` of the server takes
libfiu's global rwlock and a hash lookup, also after
`SYSTEM DISABLE FAILPOINT`. `Aggregator::drainAdaptivePartition` checks one
per inserted key. The `iceberg_suite_*_synthio_*` tests of ClickHouse#119976 enable a
failpoint, and the job runs all tests of a shard on the same two servers in
name order, so since 2026-10-28 every test sorted after them is measured on
such servers: about 17 tests 1.3-24x slower and noisier on both arches
(`removing_group_by_keys #0` 0.13 -> 1.46 s on amd).

Order the failpoint tests last in the job's test list, in compare.sh's
confirmation reruns and in its standalone `run_tests`. The compare.sh paths
do not measure when the order cannot be computed: the confirmation is
skipped (original verdicts kept) and `run_tests` exits 1.

Related: ClickHouse#100759

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

groeneai commented Nov 4, 2026

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

Own cold review + Gate B (codex) on 977e39093f92: 0 blockers, 0 majors.

Finding Verdict
💡 compare.sh: the new lines add shellcheck SC2046/SC2128/SC2178 warnings (intended word splitting of the test list; same classes as the neighbouring lines). No shellcheck leg in the style check. noted, not blocking
💡 Only <failpoint action="enable"> is detected; a raw SYSTEM ENABLE FAILPOINT in a <query> would not be ordered last. No perf test does that today. noted, not blocking

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Master amd_release binary, one clickhouse local process: 10M-key GROUP BY 0.065-0.096 s, then 2.34-2.54 s after SYSTEM ENABLE + DISABLE FAILPOINT s3_slow_response (3 of 3 runs; control without the two statements flat).
b Root cause explained? libfiu's has_any_failpoint_been_registered is set by the first fiu_enable and never reset, so every later fiu_do_on takes a global rwlock and a hash lookup; drainAdaptivePartition checks one per key; the perf job runs all tests of a shard on the same two servers in name order, and the synthio tests sort before ~90 others.
c Fix matches root cause? Yes. No measured test shares a server process with an earlier failpoint any more; nothing is skipped, no threshold changed.
d Test intent preserved / new tests added? Test-infrastructure change: no self-test (#119766); validated locally (order on the real tree for all 6 shards, CLI, both compare.sh paths incl. their refusal).
e Both directions demonstrated? Yes. perf.py on two servers: 2.38 / 2.44 s in the master order, 0.073 / 0.079 s in the new order (2 arms each, fresh servers).
f Fix is general across code paths? Yes: job test list (all modes), confirmation reruns (in-tree and dashboard), standalone run_tests; profile collection already skips failpoint tests.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes: failpoints via <include>, missing files (keep their place), empty lists, relative and absolute test paths, nightly with calibration.xml.
h Backward compatible? (maintainer-approved exception only) Yes: test order only, independent of the reference binary.
i Invariants and contracts preserved? Yes: same test set, other tests keep their relative order; confirm_changes stays fail-open for the job (returns before any restart, no demotion).

Session id: cron:clickhouse-impl-slot-41:20261104-162100

@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @egor-click, could you review this and add the can be tested label so CI runs? The first SYSTEM ENABLE FAILPOINT keeps every later failpoint check of the server on libfiu's locked slow path, so the tests sorted after the iceberg_suite_*_synthio_* tests ran 1.3-24x slower; this runs the failpoint tests last in the job, the confirmation reruns and run_tests.

@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e9d1a2c]

Summary: ✅


AI Review

Summary

Updates libfiu so its fast-path flag is cleared when the last registered failpoint is disabled, restoring normal performance for subsequent tests sharing the server. Reviewed head e9d1a2cc574fdaad3f8cf69919979ca8c5eb2788, including the underlying submodule changes and all prior discussion. No unresolved actionable findings. A focused C-library check reproduces the stale flag with the old submodule and passes with the new one, covering replacement, wildcards, alternate enable APIs, one-time points, resizing, and concurrent enable/disable operations. The earlier inline finding concerns a reverted change and remains resolved.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors labels Nov 4, 2026
@Algunenano

Copy link
Copy Markdown
Member

@groeneai I don't like this. Instead we should prevent any performance tests to use failpoints. Please ping the authors and adjust the tests or remove them, and add a check to prevent it happening again

@Algunenano Algunenano self-assigned this Nov 4, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). label Nov 4, 2026
groeneai and others added 2 commits November 4, 2026 18:31
…r tests"

This reverts commit 977e390. The
performance tests must not use failpoints at all instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
libfiu never leaves its slow path once the first failpoint is enabled:
`has_any_failpoint_been_registered` is set by `fiu_enable` and never
reset, so from then on every `fiu_do_on` of the server process takes a
global rwlock and a hash lookup. The perf job runs all the tests of a
shard on the same two servers, so the `iceberg_suite_*_synthio_*` tests
(ClickHouse#119976), which enable `s3_slow_response` or
`local_object_storage_slow_response`, made every test that ran after them
slower and noisier: a 10M-key GROUP BY checks a failpoint per key, and
`removing_group_by_keys` went from 0.1% to 28% of master runs with a
difference over 10% on amd (ClickHouse#100759).

Each of these tests is a twin of an `iceberg_suite_*` test that only adds
the failpoint, so without it they would duplicate the existing tests.
Remove them, together with the `<failpoint>` element of `perf.py` (and
its handling in test discovery and profile collection), which nothing
else uses. The style check now rejects a failpoint in any performance
test, fragment or file they pull in with a `file` attribute (the
`tests/benchmarks` query files), both the element and a
`SYSTEM ENABLE|DISABLE FAILPOINT` statement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai changed the title Perf CI: run the tests that enable a failpoint after the other tests Perf CI: do not use failpoints in performance tests Nov 4, 2026
@groeneai

groeneai commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Done in 29f7e81, on top of a revert of the ordering commit:

  • Removed the 8 iceberg_suite_*_synthio_* tests. Each one only adds s3_slow_response or local_object_storage_slow_response to an existing iceberg_suite_* test, so without the failpoint they would be duplicates.
  • Removed the <failpoint> element of perf.py, and its handling in test discovery and profile collection.
  • New style check no_failpoints_in_performance_tests: rejects a <failpoint> element or a SYSTEM ENABLE|DISABLE FAILPOINT statement in a performance test, a fragment, or a file they pull in with file= (the tests/benchmarks queries).

@arsenmuk, these were your tests from #119976. After the first SYSTEM ENABLE FAILPOINT, libfiu keeps every failpoint check of the server on a locked path until the server restarts, so the tests that ran after them on the same servers were 1.3-24x slower (#100759). I did not find a way to add that latency without a failpoint, so I removed them. The two failpoints are still in src/ if you want to move these scenarios to an integration test.

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Nov 4, 2026
Comment thread ci/jobs/check_style.py Resolved
`FAILPOINT_STATEMENT_RE` is built for the stateless-test checks, which need
the fail point name, so it misses statements the server accepts:
`SYSTEM ENABLE FAILPOINT "s3_slow_response"` (double-quoted identifier),
`SYSTEM /* setup */ ENABLE FAILPOINT ...` (comment between keywords) and
`SYSTEM&ClickHouse#10;ENABLE FAILPOINT ...` (XML character reference).

The prohibition does not need the name, so match the word `failpoint(s)`
anywhere in the file, after decoding character references the way the XML
parser in `perf.py` does (that also covers `FAILPO&ClickHouse#73;NT` and an encoded
`file` path). The word also matches the `<failpoint>` element. No file in
tests/performance or the files it pulls in mentions it today.

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

Copy link
Copy Markdown
Member

@Algunenano Iceberg performance depends on the number and the parallelism of IO requests much more than on the CPU performance. Which means - emulating slow IO is one of a few useful ways of testing Iceberg.

@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

The slow-IO tests can be kept without slowing down the tests after them. The side effect is only libfiu's has_any_failpoint_been_registered (the fast-path flag added in contrib/libfiu): the first fiu_enable sets it and fiu_disable never clears it, so afterwards every fiu_do_on in the server takes libfiu's lock and hash lookup. On the master amd_release binary, one server, a 10M-key GROUP BY: 0.06-0.09 s fresh, 2.2-2.3 s after SYSTEM ENABLE + SYSTEM DISABLE FAILPOINT s3_slow_response, 0.06-0.09 s again after setting the flag back to 0 with gdb.

So the fix can be in libfiu: clear the flag when the last enabled failpoint is disabled. @Algunenano, which do you prefer: (1) that libfiu fix, with the 8 iceberg_suite_*_synthio_* tests restored and without the new style check, or (2) this PR as it is?

@arsenmuk

arsenmuk commented Nov 5, 2026

Copy link
Copy Markdown
Member

@alexey-milovidov

Iceberg performance depends on the number and the parallelism of IO requests much more than on the CPU performance. Which means - emulating slow IO is one of a few useful ways of testing Iceberg.

As much as I believe we'd benefit from having Iceberg perf tests with simulated lags, it's okay if we can't currently accept failpoint-based solution. I'm working on some new suites in Stresshouse which would have that via failpoints and/or tc

@Algunenano thank you for sorting this one out!

@Algunenano

Copy link
Copy Markdown
Member

@groeneai Fix it in libfiu please

groeneai and others added 3 commits November 5, 2026 09:37
Reverts 29f7e81 and 82a8d47: the slowdown after a fail point
is fixed in libfiu instead, so the iceberg_suite_*_synthio_* tests, the
<failpoint> element of perf.py and its handling come back, and the
no_failpoints_in_performance_tests style check goes away.

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

has_any_failpoint_been_registered was set by the first fiu_enable() and
never cleared, so after one SYSTEM ENABLE + DISABLE FAILPOINT every
fiu_do_on() in the server kept taking libfiu's lock and a table lookup
until a restart. In the performance tests that slowed down every test
that ran after a fail point test on the same servers.

ClickHouse/libfiu#8

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the libfiu update the flag is cleared once no fail point is enabled.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai changed the title Perf CI: do not use failpoints in performance tests Clear libfiu's fast-path flag when the last fail point is disabled Nov 5, 2026
@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Done in ClickHouse/libfiu#8: has_any_failpoint_been_registered now means "at least one fail point is enabled", recomputed under libfiu's write lock on every enable and disable. In this PR:

  • 73ed5bc points contrib/libfiu at that PR's head. I will move it to the merged commit once it is merged.
  • 1140f15 reverts the removal of the 8 iceberg_suite_*_synthio_* tests and the no_failpoints_in_performance_tests style check, so the diff is now the submodule plus one comment (2c18312).

Debug builds, one server, a 3M-key GROUP BY: master takes 0.026 s fresh and 0.73-0.80 s after SYSTEM ENABLE + DISABLE FAILPOINT; with this PR 0.021-0.064 s after the same, slow only while a fail point is enabled, and fail points still fire. One case is unchanged: a one-time fail point that has already fired keeps the flag set until it is disabled (perf.py disables every fail point it enabled).

@clickhouse-gh clickhouse-gh Bot added comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. and removed comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). labels Nov 5, 2026
@Algunenano

Copy link
Copy Markdown
Member

@groeneai I've merged the contrib, please update it here

@snelheidai

Copy link
Copy Markdown

This fixes the tests that run after a synthio test. The synthio tests themselves still run their queries with a fail point enabled, so every fiu_do_on in those queries takes libfiu's lock and hash lookup, and the adaptive aggregation merge does that once per new key (fiu_do_on(adaptive_aggregation_drain_create_states_throw, ...) in src/Interpreters/AdaptiveAggregation/Merge.cpp). For high-cardinality GROUP BY, the synthio TPC-H results therefore include that lock, not only the simulated IO latency.

On the master aarch64 binary b4fae47 (2026-10-27), Graviton3 with 4 vCPUs, warm clickhouse local over IcebergLocal tpch_ice10, with storage_cluster_read_sleep enabled (it never fires on this path, so only libfiu's check differs): TPC-H Q18's inner query (SELECT l_orderkey FROM lineitem GROUP BY l_orderkey HAVING sum(l_quantity) > 300, 15M keys) takes 0.58-0.61 s without the fail point and 2.61-2.63 s with it (4.4x). Q3 is about 4% slower (1.79 -> 1.87 s); Q1 (4 groups) is not slower. That binary predates ClickHouse/libfiu#8, which does not change this case, and Merge.cpp and FailPoint.h are unchanged since.

Possible fixes, not tested: read the fail point once per drain call instead of once per key, or add a lock-free per-fail-point enabled check in FailPoint.h; or keep aggregation-heavy queries out of the synthio suites. A change in that loop needs its own perf run: #127172, which removed per-row LIMIT BY fail points, was closed because the new loop layout was slower on arm.

@clickhouse-gh clickhouse-gh Bot added the submodule changed At least one submodule changed in this PR. label Nov 5, 2026
@snelheidai

Copy link
Copy Markdown

Here is a measured patch for the first fix suggested in #129334 (comment). drainAdaptivePartition evaluates adaptive_aggregation_drain_create_states_throw at the first new key of each drain and reuses the result, so a drain takes libfiu's lock at most once instead of once per new key. The fail point is ONCE, so 05401_adaptive_aggregator_broken_shared_drain still gets FAULT_INJECTED. The only behaviour change: a fail point enabled after a drain's first new key fires at the next drain instead of the next key.

Release builds (clang-21) of master da712df with and without the patch (it applies unchanged to current master), Graviton3 with 4 vCPUs, warm clickhouse local over MergeTree tables. Times are per-round medians of 8 runs, averaged over 6 ABBA rounds; results are identical in every case.

GROUP BY State master patch patch/master (95% CI)
10M distinct String keys after SYSTEM ENABLE + DISABLE FAILPOINT¹ 1422 ms 202 ms 0.143 (0.132–0.154)
fresh process 204.5 ms 203.3 ms 0.994 (0.983–1.005)
sum(v), 30M rows, 9.5M UInt64 keys after SYSTEM ENABLE + DISABLE FAILPOINT¹ 1631 ms 404 ms 0.248 (0.230–0.267)
fresh process 407.1 ms 410.2 ms 1.008 (1.001–1.014)

¹ On this pre-libfiu#8 build, that state sends every fiu_do_on through libfiu's locked lookup, as happens while any fail point is enabled: the synthio case that remains after this PR.

count() over the same keys, whose path has no fail point check, is unchanged in both states. The fresh sum(v) case is 0.8% slower, and x86 was not measured. #127172 showed that this kind of loop change can be slower on arm, so the CI performance run should confirm the fresh path.

@groeneai, would you fold this into this PR, or take it as a separate PR with its own performance run?

Patch
--- a/src/Interpreters/AdaptiveAggregation/Merge.cpp
+++ b/src/Interpreters/AdaptiveAggregation/Merge.cpp
@@ -4,6 +4,7 @@
 
 #include <algorithm>
 #include <bit>
+#include <optional>
 
 #include <AggregateFunctions/IAggregateFunction.h>
 #include <Columns/ColumnString.h>
@@ -426,6 +427,21 @@
     using Key = AdaptiveRecordKey<Method>;
     const bool prefetch = prefetchesStagedKeys<Key>(table);
     StagedRecordWalk walk;
+
+    /// Once any failpoint is enabled, every failpoint check takes libfiu's global lock, so a check per new key
+    /// serializes the drains of all threads. Check once per drain, at its first new key (the failpoint is ONCE).
+    std::optional<bool> fail_creating_states;
+    auto throw_if_creating_states_fails = [&]() ALWAYS_INLINE
+    {
+        if (!fail_creating_states.has_value()) [[unlikely]]
+        {
+            fail_creating_states = false;
+            fiu_do_on(FailPoints::adaptive_aggregation_drain_create_states_throw, { fail_creating_states = true; });
+        }
+        if (*fail_creating_states) [[unlikely]]
+            throw Exception(ErrorCodes::FAULT_INJECTED, "Injected fault while creating the states of a merged key");
+    };
+
     visitStagedRecordFormat<Key>(adaptive_argument_layout.get(), is_simple_count, [&]<typename Record>(Record format) ALWAYS_INLINE
     {
         if constexpr (Record::with_count)
@@ -473,10 +489,7 @@
                             it->getMapped() = nullptr;
                             /// Stands for the creation of the states failing, as on a memory limit: the key stays
                             /// in the table with a null state.
-                            fiu_do_on(FailPoints::adaptive_aggregation_drain_create_states_throw,
-                            {
-                                throw Exception(ErrorCodes::FAULT_INJECTED, "Injected fault while creating the states of a merged key");
-                            });
+                            throw_if_creating_states_fails();
                             AggregateDataPtr place = arena->alignedAlloc(total_size_of_aggregate_states, align_aggregate_states);
                             createAggregateStates(place);
                             it->getMapped() = place;
@@ -510,10 +523,7 @@
                         it->getMapped() = nullptr;
                         /// Stands for the creation of the states failing, as on a memory limit: the key stays
                         /// in the table with a null state.
-                        fiu_do_on(FailPoints::adaptive_aggregation_drain_create_states_throw,
-                        {
-                            throw Exception(ErrorCodes::FAULT_INJECTED, "Injected fault while creating the states of a merged key");
-                        });
+                        throw_if_creating_states_fails();
                         AggregateDataPtr place = arena->alignedAlloc(total_size_of_aggregate_states, align_aggregate_states);
                         createAggregateStates(place, use_compiled_functions);
                         it->getMapped() = place;

Same tree as the previously pinned PR head f4a1ef5f668c.

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

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, done: contrib/libfiu now points at the merge commit ClickHouse/libfiu@10c7bbf (same tree as the PR head), in e9d1a2c.

@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e9d1a2cc5 with master bdbd1b837 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of b02fbee24; 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.

Compile time of recompiled translation units

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

Job report

@Algunenano
Algunenano added this pull request to the merge queue Nov 10, 2026
Merged via the queue into ClickHouse:master with commit 7814418 Nov 10, 2026
186 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 10, 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-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. manual approve Manual approve required to run CI pr-ci pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants