Macaw.Data.Manager.Budget (macaw_data v0.21.1)

View Source

The host's memory budget for its source managers (spec/01 §6.4.6, dco-tek/macaw/macaw#108 "Memory"): the supervisor's memory: option, the bytes every manager's chunks may hold together, shared among them by what each holds.

Each manager puts its chunks' bytes (Macaw.Data.Source.Manager.info/1, as the BEAM sizes them) in the supervisor's budget table after each publication. When the host's total passes the budget, each manager's share is the budget in proportion to what it holds (share/3), and every manager over its share evicts down to it (Macaw.Data.Source.Manager.evict/2): the chunks no reader covers, the oldest and cheapest to read again first, the open chunk and every covered chunk never. A manager that ends leaves the table (its row deleted by its table's heir, the supervisor's <name>.Tables).

holders/1 names the processes holding the most binary memory, as recon's bin_leak/1 finds them, so a process keeping evicted chunks alive is named by Macaw.Data.Manager.memory/1.

Summary

Functions

The supervisor's budget in bytes, nil for none.

The n processes holding the most binary memory: [%{pid:, bytes:, name:}], most first, each binary counted once a process, name its registered name or its initial call.

The manager of key out of the budget.

Whether the host's managers together hold more than budget.

The manager of key holding mine bytes: {:ok, share} when the host's managers together hold more than budget and this one's share of it is under what it holds, else :fits.

A manager's share of budget: all of it while the host's total fits, else the budget in proportion to the mine it holds.

The budget's table of each manager's bytes, by manager key.

Functions

bytes(sup)

@spec bytes(atom()) :: pos_integer() | nil

The supervisor's budget in bytes, nil for none.

holders(n)

@spec holders(pos_integer()) :: [map()]

The n processes holding the most binary memory: [%{pid:, bytes:, name:}], most first, each binary counted once a process, name its registered name or its initial call.

leave(sup, key)

@spec leave(atom(), term()) :: :ok

The manager of key out of the budget.

over?(sup, budget)

@spec over?(atom(), pos_integer()) :: boolean()

Whether the host's managers together hold more than budget.

put(sup, key, mine, budget)

@spec put(atom(), term(), non_neg_integer(), pos_integer()) ::
  {:ok, non_neg_integer()} | :fits

The manager of key holding mine bytes: {:ok, share} when the host's managers together hold more than budget and this one's share of it is under what it holds, else :fits.

share(budget, mine, total)

A manager's share of budget: all of it while the host's total fits, else the budget in proportion to the mine it holds.

iex> Macaw.Data.Manager.Budget.share(1_000, 300, 800)
1000
iex> Macaw.Data.Manager.Budget.share(1_000, 300, 1_500)
200

table(sup)

@spec table(atom()) :: atom()

The budget's table of each manager's bytes, by manager key.