AuroraMeter.Broadcaster (Aurora Meter v0.3.0)

View Source

Fans live counter values out over Phoenix.PubSub on an interval, decoupled from the (slower) database flush, and ships this node's deltas to the other nodes.

Each tick, for every counter touched since the previous tick:

  • the delta this node accumulated since its last tick (pending_gossip) is taken and collected; one {:aurora_meter, :deltas, node, [...]} message per tick goes to AuroraMeter.Cluster on every other node
  • period counters are broadcast on their tenant topic ("aurora_meter:tenant:" <> tenant_key) as {:aurora_meter, :usage, %{feature:, value:, period_start:}}

With cluster sync on (the default) tenant broadcasts are node-local: every node informs its own LiveViews from its own converged view, so a browser connected to node B never receives node A's slightly different number. With cluster_sync: false they fan out cluster-wide as before.

The touched set is independent of the flusher's dirty set, so a flush landing between a track and the next tick can never swallow an update.

Summary

Functions

Broadcasts touched counters now, returning :ok.

Returns a specification to start this module under a supervisor.

The PubSub topic for a tenant's usage updates.

Functions

broadcast_now()

@spec broadcast_now() :: :ok

Broadcasts touched counters now, returning :ok.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

topic(tenant_key)

@spec topic(String.t()) :: String.t()

The PubSub topic for a tenant's usage updates.