Repository navigation
Add :off_heap option to Registry - #15992
Merged
josevalim merged 3 commits intoOct 16, 2026
Merged
Conversation
Contributor
Author
|
This PR is a follow up to switch to |
josevalim
requested changes
Oct 15, 2026
wwitek-whatnot
force-pushed
the
wwitek/off-heap-registry
branch
from
October 15, 2026 15:13
a76ff38 to
2d844c3
Compare
josevalim
requested changes
Oct 15, 2026
josevalim
left a comment
Member
There was a problem hiding this comment.
Sorry, just one other tiny change needed!
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.
Background
In our production system, when a lot of users disconnect at the same time from a single Phoenix channel, we run into very high queues that put pressure on GC and the results is that the queues never go down. We tested using off-heap message queue for the PubSub`s registry and it helped, so we'd like to introduce that as an option for PubSub, starting with an option for Registry.
Changes
Adds an:off_heapstart option toRegistry(defaultfalse) that setsmessage_queue_data: :off_heapon the registry's partition processes.Adds
spawn_optthat are passed to Registry partitions.Benchmark
Benchmark simulates a crash storm: a single-partition registry with N linked registrants, the partition process suspended (via
:sys.suspend/1) so:EXITmessages accumulate in its mailbox instead of being processed as they arrive, then all N registrants killed at once. Measures the time for an explicit:erlang.garbage_collect/1and the time to resume and fully drain the mailbox.Results:
At 100k queued
:EXITmessages, draining the backlog takes ~3.28s with the default:on_heapbehavior vs. ~66ms withoff_heap: true— roughly 50x faster.Testing
Added tests covering: the
:off_heapoption is validated as a boolean, partitions run with:on_heapmessage queue data by default, and partitions run with:off_heapmessage queue data when the option is enabled.