rabbit_db: Fix handling of async m2k puts (backport #15480)#15522
Merged
rabbit_db: Fix handling of async m2k puts (backport #15480)#15522
Conversation
[Why] Several `rabbit_db_*_m2k_converter` modules use async puts to Khepri to parallelize writes and make them faster. This is handled by the `rabbit_db_m2k_converter:with_correlation_id/2` function. Ra will send back a Ra event message for each async write to reply with the result of the write. The problem is that the code behind `with_correlation_id/2` has a logic issue: it only consumes 1 Ra event every 64 async writes. It will consume all of them at the end of the overall, but meeawhile, messages will accumulate. If there are a lot of Mnesia records to copy, this can fill the process mailbox and slow it down significantly. [How] The logic is changed to regularily consume all messages in the mailbox with a timeout of 0. Only at the end, remaining messages are consumed with an infinity timeout because we know how many messages we are expecting (the actual timeout is handled by the write itself). While here, delete debug log messages logged for each async puts. With a significant number of puts, this noticably slows down the process. (cherry picked from commit c6415de)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Several
rabbit_db_*_m2k_convertermodules use async puts to Khepri to parallelize writes and make them faster. This is handled by therabbit_db_m2k_converter:with_correlation_id/2function.Ra will send back a Ra event message for each async write to reply with the result of the write. The problem is that the code behind
with_correlation_id/2has a logic issue: it only consumes 1 Ra event every 64 async writes. It will consume all of them at the end of the overall, but meeawhile, messages will accumulate. If there are a lot of Mnesia records to copy, this can fill the process mailbox and slow it down significantly.How
The logic is changed to regularily consume all messages in the mailbox with a timeout of 0. Only at the end, remaining messages are consumed with an infinity timeout because we know how many messages we are expecting (the actual timeout is handled by the write itself).
This is an automatic backport of pull request #15480 done by Mergify.