Ferricstore.MemoryBudget (ferricstore v0.4.2)

Copy Markdown View Source

Central sizing policy for memory-sensitive queues and caches.

The limits here are startup/default guardrails. Live pressure response still belongs to Ferricstore.MemoryGuard; this module decides the safe default size for structures that otherwise grow independently of MemoryGuard:

  • WARaft segment-log ETS tail cache
  • WARaft apply-projection cache before segment projection compaction
  • Flow history projector pending queue
  • Flow LMDB writer mailbox and per-enqueue batch size

Explicit application env always wins. When a key is unset, defaults are derived from RAM, disk free space, CPU count, and shard count.

Summary

Functions

Returns all adaptive limits for a hardware profile.

Returns the hardware profile used by adaptive limits.

Returns a configured or adaptive limit for a guardrail key.

Clears the cached adaptive default snapshot.

Types

limit_key()

@type limit_key() ::
  :flow_history_projector_max_pending_entries
  | :flow_lmdb_writer_max_mailbox_messages
  | :flow_lmdb_writer_max_enqueue_ops
  | :waraft_segment_log_max_ets_bytes
  | :waraft_segment_log_max_ets_entries
  | :waraft_segment_log_min_ets_entries
  | :waraft_apply_projection_cache_max_entries

Functions

adaptive_limits(profile \\ hardware_profile())

@spec adaptive_limits(map() | keyword()) :: map()

Returns all adaptive limits for a hardware profile.

hardware_profile(opts \\ [])

@spec hardware_profile(keyword()) :: map()

Returns the hardware profile used by adaptive limits.

limit(key, default \\ :infinity)

@spec limit(atom(), non_neg_integer() | :infinity) :: non_neg_integer() | :infinity

Returns a configured or adaptive limit for a guardrail key.

false, :infinity, "off", "false", and "infinity" intentionally disable a cap and return :infinity.

reset_cache()

@spec reset_cache() :: :ok

Clears the cached adaptive default snapshot.

Production code normally keeps one startup-sized snapshot so hot-path callers do not rescan RAM/disk/CPU state. Tests and config reload paths can reset it before constructing new workers.