View Source Pogo.DynamicSupervisor (Pogo v0.3.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 Types

@type init_option() ::
  Supervisor.init_option()
  | {:scope, term()}
  | {:sync_interval, pos_integer()}
  | {:children, [Supervisor.child_spec()]}
@type option() :: {:name, Supervised.name()}

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

start_child(supervisor, child_spec)

View Source
@spec start_child(
  Supervisor.supervisor(),
  Supervisor.child_spec() | {module(), term()} | module()
) ::
  :ok | {:error, any()}

Requests a child process to be started under one of the supervisors in the cluster.

@spec start_link([option() | init_option()]) :: 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 scope
  • sync_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 to 5_000
  • children - list of child specifications to automatially start in the cluster

Children specified at startup are handled in the same way as children started dynamically. The only difference is that when Pogo.DynamicSupervisor runs under a supervision tree and is restarted, it will automatically restart all these children as well.

Link to this function

terminate_child(supervisor, id)

View Source
@spec terminate_child(Supervisor.supervisor(), term()) :: :ok

Requests a child process running under one of the supervisors in the cluster to be terminated.

Link to this function

which_children(supervisor, scope)

View Source
@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.