View Source Pogo.DynamicSupervisor (Pogo v0.1.0)
Dynamic Supervisor that distributes processes among nodes in the cluster.
Uses process groups (via :pg
) under the hood to maintain cluster-wide
state and coordinate work between supervisor processes running in the
cluster. Supervisors are organized into independent scopes.
When a supervisor receives a request to start a child process via
start_child/2
, instead of starting it immediately, it propagates that
request via process groups to supervisors running on other nodes.
Termination of child processes via terminate_child/2
works in the same
way.
Each supervisor periodically synchronizes its local state by processing the start and terminate requests, and updates child process information in cluster-wide state.
Supervisor processes running on different nodes, but operating within the same scope, form a hash ring. When processing requests to start child processes, supervisors use consistent hashing to determine if they should accept the request or not, guaranteeing that there will be exactly one supervisor accepting the request and actually starting the child process locally.
Cluster topology changes, with supervisors being added or removed, are likely to affect the distribution of child processes - some child processes may get rescheduled to supervisors running on different nodes.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Requests a child process to be started under one of the supervisors in the cluster.
Starts local supervisor and joins cluster-wide scoped process group.
Requests a child process running under one of the supervisors in the cluster to be terminated.
Returns a list with information about locally or globally supervised children.
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
@spec start_child( Supervisor.supervisor(), Supervisor.child_spec() | {module(), term()} | module() ) :: :ok
Requests a child process to be started under one of the supervisors in the cluster.
@spec start_link(keyword()) :: GenServer.on_start()
Starts local supervisor and joins cluster-wide scoped process group.
options
Options
All options accepted by Supervisor.init/2
are also accepted here, except for
:strategy
which is always :one_for_one
. Additionally the following options
can be specified.
scope
- scope to join, supervisors only cooperate with other supervisors operating within the same scopesync_interval
- interval in milliseconds, how often the supervisor should synchronize its local state with the cluster by processing requests to start and terminate child processes, defaults to5_000
@spec terminate_child(Supervisor.supervisor(), term()) :: :ok
Requests a child process running under one of the supervisors in the cluster to be terminated.
@spec which_children(Supervisor.supervisor(), :global | :local) :: [ {term() | :undefined, Supervisor.child() | :restarting, :worker | :supervisor, [module()] | :dynamic} ]
Returns a list with information about locally or globally supervised children.