Repository navigation
Reuse RabbitMQ producer connections and channels across INSERT queries - #127611
alexey-milovidov merged 5 commits into
Conversation
|
Workflow [PR], commit [60380c3] Summary: ✅
AI ReviewSummaryThis PR adds optional reuse of 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 sizes6 object files changed (+210.87 KiB total), 2 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 units15 translation units recompiled, 47 s compile time in total, 13 of them have a recent master baseline. |
antaljanosbenjamin
left a comment
There was a problem hiding this comment.
Apart from this small comment, the PR looks pretty good!
|
@antaljanosbenjamin Is there anything else for me to do? I see that there are some CI failures but I can't access them. |
|
I think the failures are not related, will check them later (I am out of office these days, but will try to merge it). |
|
🕵 Merged the latest |
515a8d9
…l-on-table-shutdown Resolve the conflict with ClickHouse#127611, which moved the producer loop into `RabbitMQPublisher::publishStep` and pools publishers between inserts. The loop on master still stops silently on `shutdown_called`, so the shutdown check is kept as the first step of each iteration: it closes `payloads` and throws `ABORTED`. On that path `can_reuse_publisher` stays false, so `finishImpl` disconnects the publisher instead of returning a channel with unconfirmed messages to the pool. `CANNOT_CONNECT_RABBITMQ` is no longer used in this file after the merge and is dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n-delivery-tag Master moved the publisher confirms handling (`removeRecord`, `delivery_record`, `returned`) from `RabbitMQProducer` into the new `RabbitMQPublisher` class (#127611). Resolve the conflict by taking master's `RabbitMQProducer.cpp`, porting the fix for unknown delivery tags to `RabbitMQPublisher::removeRecord`, moving the test friend declaration to `RabbitMQPublisher`, and renaming the unit test to `gtest_rabbitmq_publisher.cpp` to drive `RabbitMQPublisher`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #127611 to 26.8: Reuse RabbitMQ producer connections and channels across INSERT queries
Cherry pick #127611 to 26.9: Reuse RabbitMQ producer connections and channels across INSERT queries
Cherry pick #127611 to 26.10: Reuse RabbitMQ producer connections and channels across INSERT queries
…nnels across INSERT queries
…nnels across INSERT queries
…annels across INSERT queries
The backport of #127611 moved the publisher confirms state (`delivery_record`, `returned`, `removeRecord`) from `RabbitMQProducer` to `RabbitMQPublisher`. The unit test from the backport of #131731 still constructed `RabbitMQProducer` and used these members, so `unit_tests_dbms` did not compile in the debug, sanitizer and `arm_darwin` builds. Test `RabbitMQPublisher` directly, as on master after #131731: the test is `RabbitMQPublisherTest` in `gtest_rabbitmq_publisher.cpp`, and the `friend` declaration moves from `RabbitMQProducer` to `RabbitMQPublisher`. The test cases do not change. #134083
The backport of #127611 moved the publisher confirms state (`delivery_record`, `returned`, `removeRecord`) from `RabbitMQProducer` to `RabbitMQPublisher`. The unit test from the backport of #131731 still constructed `RabbitMQProducer` and used these members, so `unit_tests_dbms` did not compile in the debug, sanitizer and `arm_darwin` builds. Test `RabbitMQPublisher` directly, as on master after #131731: the test is `RabbitMQPublisherTest` in `gtest_rabbitmq_publisher.cpp`, and the `friend` declaration moves from `RabbitMQProducer` to `RabbitMQPublisher`. The test cases do not change. #134084
The backport of #127611 moved the publisher confirms state (`delivery_record`, `returned`, `removeRecord`) from `RabbitMQProducer` to `RabbitMQPublisher`. The unit test from the backport of #131731 still constructed `RabbitMQProducer` and used these members, so `unit_tests_dbms` did not compile in the debug, sanitizer and `arm_darwin` builds. Test `RabbitMQPublisher` directly, as on master after #131731: the test is `RabbitMQPublisherTest` in `gtest_rabbitmq_publisher.cpp`, and the `friend` declaration moves from `RabbitMQProducer` to `RabbitMQPublisher`. The test cases do not change. #134085
Backport #127611 to 26.9: Reuse RabbitMQ producer connections and channels across INSERT queries
Backport #127611 to 26.8: Reuse RabbitMQ producer connections and channels across INSERT queries
Motivation
Every
INSERTinto aRabbitMQtable created a newRabbitMQProducer, which opened its own connection and channel synchronously on the inserting thread and closed both at the end. Every insert paid a full AMQP handshake cost, even when it wrote no rows. No rows may be a common case for a materialized view with a filter: it fires on every insert into its source table and pays the full cost each time.The issue also describes the 200 ms polling sleep in
RabbitMQConnection::connectImpl. That is not addressed here and it can be fixed separately.Related: #122943
Changes
rabbitmq_max_idle_producer_connections, default0(the previous behavior). When set, the table keeps up to that many idle connections, each with an open confirm-mode channel, for subsequent inserts. It does not limit concurrency: each running insert borrows its own connection, and connections returned beyond the limit are closed.RabbitMQProducerinto a newRabbitMQPublisher. The channel callbacks previously captured the producer, so they would have outlived it on a reused channel. Most ofRabbitMQPublisher.cppis code moved fromRabbitMQProducer.cpp. The producer now only borrows a publisher and passes it messages.RabbitMQPublisherPool, one per table:Connection.Close, then the connection and channel state is checked.RabbitMQHandler::onNegotiatenow records that interval.RabbitMQPublisher::connectwaits for the channel to become ready, bounded byBLOCKING_LOOP_TIMEOUT_MS. Before, the producing task waited for it. Without this, an insert without rows finished beforeonReadyfired, so its publisher was never reusable.StorageRabbitMQ::shutdowncloses the idle connections, also when streaming to views is disabled.Results
Local run: native macOS build,
rabbitmq:4-management-alpinein Docker, the reproduction from the issue. Ten inserts into the source table (nine without rows, the last with 100 rows),view_duration_msof each materialized view:rabbitmq_max_idle_producer_connections = 0: 1280, 1232, 1232, 1228, 1235, 1250, 1227, 1235, 1230, 1244 msrabbitmq_max_idle_producer_connections = 1: 1229, 0, 0, 0, 1, 7, 1, 1, 0, 19 msThis shows that only the first insert is incurring the connection setup costs. Subsequent inserts take less time.
Tests
test_rabbitmq_insert_reuses_producer_connection, using a dedicated vhost:rabbitmqctl close_all_connectionsstill succeeds and all messages arrive;DROP TABLEleaves no connections behind.test_rabbitmq_many_insertsnow sets the setting to 4, so its 10 concurrent inserters exercise concurrent borrow and release, and the closing of connections returned beyond the limit.Caveats
0, the only behavior difference is the wait for the channel inconnect. If the channel never opens, the insert now fails after the timeout instead of waiting in the producing task.consistent_hashexchanges, the routing key is the delivery tag. On a reused channel it keeps counting across inserts instead of restarting at 0.Changelog category
Changelog entry:
Add the
RabbitMQtable settingrabbitmq_max_idle_producer_connections, which keeps idle connections with their channels open and reuses them acrossINSERTqueries. This removes the connection setup from every insert, which is especially costly for materialized views that fire often, including when they write no rows. The default0keeps the previous behavior.🤖 Generated with Claude Code. Opus 5.5 xhigh effort.
Workflow [PR]
Sync PR [sync-upstream/pr/127611]
Version info
26.11.1.2693-master(included in26.11and later)26.9.39.4,26.8.47.2