Hard per-node resource accounting. One Hard runs per BEAM node (named
__MODULE__, started under Hyper.Node.Budget.Supervisor) and tracks how much
memory and disk the VMs scheduled onto this machine have reserved.
"Hard" means the limits are inviolable: a reservation that would push the
running total past the node's configured mem_max/disk_max
(Hyper.Cfg.Budget) is refused outright. Callers reserve through
with_budget/2, which holds the budget for the duration of the callback and
releases it afterwards.
Summary
Functions
Can this node run the given vm spec? :ok if yes, {:error, reason} otherwise.
Returns a specification to start this module under a supervisor.
Configured caps minus what is currently reserved.
Reserve spec's budget for the lifetime of owner.
Reserve vm_spec's budget, run callable, and release the budget afterwards.
Functions
@spec can_run(Hyper.Vm.Instance.Spec.t()) :: :ok | {:error, term()}
Can this node run the given vm spec? :ok if yes, {:error, reason} otherwise.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec headroom() :: %{mem: Unit.Information.t(), disk: Unit.Information.t()}
Configured caps minus what is currently reserved.
@spec reserve(Hyper.Vm.Instance.Spec.t(), pid()) :: :ok | {:error, term()}
Reserve spec's budget for the lifetime of owner.
Atomic: refuses ({:error, reason}) if spec does not fit remaining headroom.
On success the reservation releases automatically when owner dies.
@spec start_link(keyword()) :: GenServer.on_start()
@spec with_budget(Hyper.Vm.Instance.Spec.t(), (-> result)) :: result | {:error, term()} when result: var
Reserve vm_spec's budget, run callable, and release the budget afterwards.
Returns callable's value if the reservation succeeds, or {:error, reason}
if the node cannot fit the spec. The budget is released even if callable
raises.