Skip to content

Fix rabbitmq engine performance issues - #102711

Merged
kssenii merged 8 commits into
ClickHouse:masterfrom
jaapieaapie1:fix-rabbitmq-performance-issues
Apr 17, 2026
Merged

kssenii merged 8 commits into
ClickHouse:masterfrom
jaapieaapie1:fix-rabbitmq-performance-issues

Conversation

@jaapieaapie1

@jaapieaapie1 jaapieaapie1 commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Performance Improvement

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

Fixed excessive RabbitMQ table engine CPU usage

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Closes #62525 #50692 and #53401

Before:
screenshot-2026-04-14_21-32-10

After:
screenshot-2026-04-14_21-30-30

Ofcourse verified that all functionality stays in tact and it still recovers from errors like disconnections from rabbitmq.

Version info

  • Merged into: 26.4.1.1015
  • Backported to: 26.3.10.45

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Apr 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e1b7b00]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, AsyncInsert, s3 storage, parallel) failure
04060_transaction_snapshot_visibility FAIL cidb IGNORED
04057_transaction_version_metadata_lifecycle FAIL cidb IGNORED

AI Review

Summary

This PR fixes RabbitMQ engine shutdown behavior under idle-loop conditions by separating background-loop stop (stopLoop) from blocking-loop wake-up (stopBlockingLoop), switching setup/cleanup callback stop calls to the blocking variant, and adding an integration regression test for prompt idle shutdown. The change is coherent across touched call sites and includes targeted coverage for the previously risky path. I did not find additional correctness, safety, or performance issues beyond already-discussed inline threads.

ClickHouse Rules
Item Status Notes
Deletion logging ✅
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Apr 14, 2026
@nikitamikhaylov

Copy link
Copy Markdown
Member

Let's fix tests.

@jaapieaapie1

Copy link
Copy Markdown
Contributor Author

@nikitamikhaylov the remaining test failure seems unrelated or a random failure?

@kssenii kssenii self-assigned this Apr 16, 2026
@kssenii
kssenii added this pull request to the merge queue Apr 16, 2026
@kssenii
kssenii removed this pull request from the merge queue due to a manual request Apr 16, 2026
@jaapieaapie1
jaapieaapie1 requested a review from kssenii April 16, 2026 17:53
@clickhouse-gh

clickhouse-gh Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 66.29% (59/89) · Uncovered code

Full report · Diff report

@jaapieaapie1

Copy link
Copy Markdown
Contributor Author

Failing test seems unrelated/flaky

@kssenii
kssenii added this pull request to the merge queue Apr 17, 2026
@kssenii

kssenii commented Apr 17, 2026

Copy link
Copy Markdown
Member

Thank you for the fix!

Merged via the queue into ClickHouse:master with commit e965b5f Apr 17, 2026
159 of 161 checks passed
@jaapieaapie1
jaapieaapie1 deleted the fix-rabbitmq-performance-issues branch April 17, 2026 10:43
@clickgapai

Copy link
Copy Markdown
Contributor

Hi — this PR may need backporting to 26.3 (LTS), 26.2, 26.1, 25.8 (LTS), but no backport label was found.

Affected code: RabbitMQHandler::startLoop busy-spinning with uv_run(UV_RUN_NOWAIT) and RabbitMQHandler::stopLoop conflating blocking/non-blocking loop stop semantics — core code present in all supported branches.

Why: The busy-spinning CPU waste in RabbitMQHandler::startLoop has existed since the RabbitMQ engine was introduced in 2020, predating all supported branches. The fix is minimal (adding yield + method split) and safe. Users on all supported branches experience 20%+ unnecessary CPU load when using RabbitMQ tables.

If this should be backported, consider adding pr-must-backport or a version-specific label (e.g. v26.3-must-backport). Ignore this if backporting is not applicable.

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 17, 2026
@jaapieaapie1

Copy link
Copy Markdown
Contributor Author

@kssenii could you add backport labels? If you agree with this needing backporting.

@kssenii kssenii added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Apr 20, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Apr 20, 2026
robot-ch-test-poll3 added a commit that referenced this pull request Apr 27, 2026
Cherry pick #102711 to 25.8: Fix rabbitmq engine performance issues
robot-ch-test-poll3 added a commit that referenced this pull request Apr 27, 2026
Cherry pick #102711 to 26.3: Fix rabbitmq engine performance issues
kssenii added a commit that referenced this pull request Apr 28, 2026
Backport #102711 to 26.3: Fix rabbitmq engine performance issues
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Apr 30, 2026
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request May 7, 2026
The three tests in `tests/integration/test_storage_rabbitmq/test_shutdown.py`
have been failing in CI:

- `test_shutdown_rabbitmq_with_materialized_view`
- `test_idle_loop_shutdown_completes_promptly`
- `test_rabbitmq_virtual_column_table`

The fourth test in the file (`test_attach_detach_rabbitmq_with_materialized_view`)
was already marked as `pytest.mark.skip` due to a known data race in
`StorageRabbitMQ` shutdown.

Per @alexey-milovidov's directive on PR ClickHouse#104253:
> "remove (or, optionally, fix) failed RabbitMQ tests and send a PR.
>  Tag the author who tried to resurrect RabbitMQ tests recently,
>  as it was a bad idea."

Removing the entire `test_shutdown.py` file rather than skipping its
contents, since the only non-skipped tests in it are flaky and the
remaining test was already non-runnable.

Context:
- The `test_storage_rabbitmq` suite was originally removed in PR ClickHouse#93107
  due to chronic flakiness, then restored in PR ClickHouse#101967 (2026-04-07).
- `test_shutdown.py` was added shortly after in PR ClickHouse#102711 (2026-04-21).

cc @alexey-milovidov @fm4v @jaapieaapie1
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 pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-performance Pull request with some performance improvements 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.

RabbitMQ leads to a high CPU load

7 participants