Distributed load balancer based on :pg.
Nodes register themselves when started so callers can pick an available node using a selection algorithm.
Summary
Functions
Selects a node and executes an RPC call through the load balancer.
Selects a node and executes an RPC cast through the load balancer.
Returns a specification to start this module under a supervisor.
Gets the nodes that are registered for the load balancer.
Releases a node after an RPC call completes.
Selects a node from the available nodes for the load balancer.
Selects multiple nodes from the available nodes for the load balancer.
Types
@type option() :: {:node_match_list, node_match_list()} | {:selection_algorithm, module()} | {:algorithm_opts, keyword()}
@type opts() :: [GenServer.option() | option()]
Functions
Selects a node and executes an RPC call through the load balancer.
Selects a node and executes an RPC cast through the load balancer.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec get_members(name()) :: ErrorMessage.t_res([node()])
Gets the nodes that are registered for the load balancer.
@spec pg_group_name() :: atom()
Releases a node after an RPC call completes.
Used by connection-tracking algorithms (e.g., Least Connections) to decrement their active connection counters.
@spec select_node( name(), keyword() ) :: ErrorMessage.t_res(node())
Selects a node from the available nodes for the load balancer.
@spec select_nodes(name(), pos_integer(), keyword()) :: ErrorMessage.t_res([node()])
Selects multiple nodes from the available nodes for the load balancer.
Useful for replication strategies where a key needs to be routed to
a primary and one or more replica nodes. Returns up to count distinct
nodes.
Algorithms that implement the choose_nodes/4 callback (e.g., HashRing)
provide consistent multi-node selection. Other algorithms fall back to
returning count randomly shuffled nodes.
@spec start_link(opts()) :: GenServer.on_start()