Xirsys.XTurn.ClientWorker.Pool (xturn v2.0.0)

Copy Markdown View Source

Supervisor and dispatcher for sharded STUN/TURN control workers.

What problem this solves

STUN/TURN control handling mutates per-request %Conn{} state and must stay ordered per client endpoint. Hashing {client_ip, client_port} to a fixed worker serializes that client's requests without a global lock while still using multiple cores across clients.

Internal note

dispatch/2 is called from socket handlers when a frame is classified as control-plane traffic.

RFCs

Summary

Functions

Returns a specification to start this module under a supervisor.

Casts frame to the worker shard for meta.client_ip / meta.client_port.

Configured pool size (:client_worker_pool_size or scheduler count).

Starts the worker pool supervisor (registered as __MODULE__).

Shard index for a client five-tuple (same hash as dispatch/2).

Registered module atom for worker index (ClientWorker.N).

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

dispatch(frame, meta)

@spec dispatch(binary(), map()) :: :ok

Casts frame to the worker shard for meta.client_ip / meta.client_port.

meta must include :transport, :socket, and server/client endpoints.

pool_size()

@spec pool_size() :: pos_integer()

Configured pool size (:client_worker_pool_size or scheduler count).

start_link(opts \\ [])

Starts the worker pool supervisor (registered as __MODULE__).

worker_index(client_ip, client_port)

@spec worker_index(:inet.ip_address(), :inet.port_number()) :: non_neg_integer()

Shard index for a client five-tuple (same hash as dispatch/2).

worker_name(index)

@spec worker_name(non_neg_integer()) :: atom()

Registered module atom for worker index (ClientWorker.N).