beacon/README.md
Beacon is a scalable process group manager. The main use case for this library is to have membership counts available on the cluster without spamming whenever a process joins or leaves a group. A node can have thousands of processes joining and leaving hundreds of groups while sending just the membership count to other nodes.
The main features are:
The package can be installed by adding beacon to your list of dependencies in mix.exs:
def deps do
[
{:beacon, "~> 1.0"}
]
end
Add Beacon to your application's supervision tree specifying a scope name (here it's :users)
def start(_type, _args) do
children =
[
{Beacon, :users},
# Or passing options:
# {Beacon, [:users, opts]}
# See Beacon.start_link/2 for the options
Now process can join groups
iex> pid = self()
#PID<0.852.0>
iex> Beacon.join(:users, {:tenant, 123}, pid)
:ok
iex> Beacon.local_member_count(:users, {:tenant, 123})
1
iex> Beacon.local_members(:users, {:tenant, 123})
[#PID<0.852.0>]
iex> Beacon.local_member?(:users, {:tenant, 123}, pid)
true
From another node part of the same scope:
iex> Beacon.member_counts(:users)
%{{:tenant, 123} => 1}
iex> Beacon.member_count(:users, {:tenant, 123})
1