-
-
Notifications
You must be signed in to change notification settings - Fork 410
feat: beacon #1664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: beacon #1664
Conversation
This comment has been minimized.
This comment has been minimized.
36c3250 to
e66554d
Compare
This comment has been minimized.
This comment has been minimized.
e66554d to
7f87fb8
Compare
josevalim
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @edgurgel! This is looking great and I have added some comments.
Keep in mind that this could be somewhat implemented with Phoenix.Tracker: you have a custom group and one counter process per node that periodically updates its metadata with the number of entries it sees. This means you can reuse all of PubSub/Tracker, its messaging and updates, while still benefiting from periodical updates. The Tracker approach should be consideraly fewer lines of code, but perhaps there are additional reasons for going ahead with Beacon!
|
PS: I will do another pass on the code after the first around of feedback, just to make sure I didn't miss anything important. Distributed code always deserves a couple rounds of looks! |
|
Oi, @josevalim ! Feliz natal! First I would like to say I'm sorry for not providing enough context in this PR description. I will try to fix this now: Today we use
We decided to build Beacon because we wanted to know how many processes belong to each group globally. We also wanted to keep some features that
We also wanted to have some control how messages are sent to the cluster as we wanted to use It obviously also must be able to quickly answer how many processes belong to a group (locally and globally). |
I have to admit I didn't even think about checking Phoenix.Tracker. I will definitely check it out next week! |
FWIW, I believe Phoenix.Tracker will immediately notify changes to metadata of a given process, so it won't fullfil all of your criteria above. Perhaps a feature could be added to postpone that until the next broadcast though, but I am not sure how trivial or complex that would be. |
josevalim
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oi @edgurgel, feliz natal para você também! 🎄
I did another pass, as promised, and I think of all my comments, the only blocker is storing a MapSet in the ETS table. The whole MapSet is copied when read and copied when written, which will make it very expensive if you have thousands of entries. If you need to track the entries, then use two separate ETS tables, one only for the entries.
I also took a look at the Registry to see if we could add the feature directly to it and I don't think we can because the counter requires a number of processes acting as partitions to monitor and manage the counter. Therefore, another option is for Beacon to track only counts, as it needs to use a different design, and keep using the Registry for the entries themselves.
The entries table now holds the actual pids and a separate table holds the counters When partition restarts it uses entries table as the source of truth
|
Thanks, @josevalim! I went with your advice and now each Partition holds two ETS tables. Because I'm already "paying" the price of doing a GenServer call I ended up using a If any crash happens the entries table is used as source of truth. If we for whatever reason crash before the counters table is updated it won't be a problem. |
|
Thanks for the review again! I've updated the code based on your comments 🙇
Yeah good point. I thought about it but I want the counters table to have the Also because I need to do an insert + update_counter there is chance that the counter is not updated and a crash happens. Then when rebuilding the counters it is easier when I can simply delete all objects from the counters table before rebuilding it. |
|
All good to me! |
What kind of change does this PR introduce?
Create new process group library called Beacon that broadcast only group counts to other nodes. Actual pids are only available to the local node. It also supports custom adapter so that we can use PubSub for the broadcasting (including regional broadcasting).
The plan is to start using Beacon without any real changes and later on start using the group data for 3 things: