Upgrade to match modern gen_server (continuation of #24)#25
Merged
michaelklishin merged 9 commits intomasterfrom Mar 18, 2026
Merged
Upgrade to match modern gen_server (continuation of #24)#25michaelklishin merged 9 commits intomasterfrom
gen_server (continuation of #24)#25michaelklishin merged 9 commits intomasterfrom
Conversation
This change roughly syncs the init_it with gen_server's. The nice part
of this is that we can now return `ignore` and `{error, Reason}` which
are supported by `gen_server` but not `gen_batch_server`. `ignore` might
be useful for `ra_log_wal` when there is no available disk space.
This bump is perfectly reasonable for any modern RabbitMQ series.
1. Type spec updates 2. A few more ports from the standard OTP `gen_server
michaelklishin
added a commit
to rabbitmq/ra
that referenced
this pull request
Mar 18, 2026
michaelklishin
added a commit
to rabbitmq/rabbitmq-server
that referenced
this pull request
Mar 18, 2026
mergify bot
pushed a commit
to rabbitmq/rabbitmq-server
that referenced
this pull request
Mar 19, 2026
See rabbitmq/gen-batch-server#25. (cherry picked from commit a586b10)
mergify bot
pushed a commit
to rabbitmq/rabbitmq-server
that referenced
this pull request
Mar 19, 2026
See rabbitmq/gen-batch-server#25. (cherry picked from commit a586b10) (cherry picked from commit 7506d9d)
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.
This is a continuation to #24 by @the-mikedavis with a few changes from me:
README.mddoc updatesgen_start/4wheresplitwith/2incorrectly could leave some options behind, so it now usespartition/2Benchmarks
Since this library is used on the hot code path in RabbitMQ, I figured benchmarking the changes is a must.
The benchmark demonstrate a 4% to 9% gain:
castworkloads gain 4-5% in terms of throughput (the RabbitMQ/Ra workloads fall into this category)callworkloads gain up to 8-9% with comparably lower latencycast_batch, perhaps as expected, gains meager 0.1% because batching largely eliminates per-operation gainsWhere Do the Gains Come From?
Apparently the modern JIT optimises the
try/catchops better thancase catch.But curiously an even nicer gain comes from a switch in
loop_batched/2where/ 2was replaced withdiv 2: the former produces an intermediary float for every call while the latter does not, eliminating a few wasted CPU cycles and memory churn.Nice! Thank you, @the-mikedavis!
RabbitMQ, Ra Compatibility
These changes should be compatible with RabbitMQ branches going back to
v3.13.x:v3.13.xusescall/3v4.0.xthroughmainuse (via Ra and Osiris) 2-tuple casts on the key code paths