Repository navigation
RabbitMQ: block in the poller instead of spinning (up to −96% CPU) - #131355
alexey-milovidov merged 4 commits into
Conversation
|
Workflow [PR], commit [1bdec60] Summary: ✅
AI ReviewSummaryThe PR replaces busy polling in Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes9 object files changed (-30.95 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units12 translation units recompiled, 42 s compile time in total, 12 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.07 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
`StorageRabbitMQ::streamToViews` stops the looping task after every block and waits for it, so the 10 ms wake timer added a delay of up to 10 ms per block. Replace the timer with an async handle: it is referenced only while `startLoop` runs (so `UV_RUN_ONCE` blocks in the poller), and `stopLoop` signals it, so the task sees the stop request immediately. Outside `startLoop` the handle is unreferenced, so the non-blocking and blocking loops still become idle. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=131355&sha=fe83f615007170f20daeebfc03aef2acadb457bf&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%203%2F8%29 ( |
|
Acknowledged. I'm investigating the |
|
The fix is in #132328. Both rows spend the extra time in |
|
Thanks for this one! 🎉 We rolled it to production today: 3 replicas, 2 Server 4.79 → 1.32 cores (−72 %); the RabbitMQ pool 3.89 → 0.33 (−92 %). Ingest unchanged. |

Closes #53401. Related: #50692, #130767
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A
RabbitMQtable that streams to materialized views no longer keeps a CPU core busy while it waits for messages.Description
Problem. Every
RabbitMQtable that streams to a view burns about one CPU core per server while it waits for messages, no matter how few arrive. Reported since 2021: #16263, #24339, #48103, #62525, #53401, #50692.Cause. The looping task calls
uv_run(UV_RUN_NOWAIT)for the whole streaming round. With the connection open there is always an active handle, so it never waits and pollsepollin a tight loop.Fix. Block in
uv_run(UV_RUN_ONCE)instead, with a repeating 10 ms timer so that the task still sees a stop request. Socket events wake it at once, so deliveries are not delayed. Nothing else changes; the timer only runs insidestartLoop(). Cost: stopping the loop takes up to 10 ms more, and a waiting round wakes 100 times per second.Result (master vs this PR, median of 3 runs each, all runs kept):
Throughput and p99 latency are unchanged; no row was lost or duplicated.
Alternative. #130767 moves the loop to a dedicated thread like
NATSHandler(+992/−439, depends on #124655). In the same benchmark it saves the same CPU. It drains a large backlog with small blocks about 2 s per million messages faster, because it does not stop the loop per block; this PR is still faster than master there (1M messages, 1000-row blocks: 11.2 s vs 13.8 s). This PR is the smaller change; #130767 is closed and kept for reference.Tests.
test_storage_rabbitmqpasses. The newtest_rabbitmq_trickle_does_not_spin_event_loopfails without the fix (985 CPU ticks in 10 s while consuming against 222 idle). The new gtestRabbitMQHandler.LoopingTaskBlocksAndStopschecks that the loop blocks, stops on request and leaves no active handle; 10 runs under TSan, no report.Benchmark setup
One machine, shared with other jobs: RabbitMQ 4.1 on 2 cores, a paced publisher with confirms on 2 others,
clickhouse serverpinned to 8 cores; a fresh server per run with aRabbitMQtable and a materialized view intoMergeTree. CPU is utime + stime of the server process. 360 msg/s usesrabbitmq_max_block_size = 1000andrabbitmq_flush_interval_ms = 5000; the others use defaults. On a quiet host the broker's CPU per message rose with either fix; with one spare core kept busy it did not, which points to idle cores entering deeper power states.Workflow [PR]
Sync PR [sync-upstream/pr/131355]
Version info
26.11.1.2654-master(included in26.11and later)