reckon_db_memory (reckon_db v1.6.0)
View SourceMemory pressure monitoring for reckon-db
Monitors system memory usage and triggers adaptive behavior when memory pressure increases. Components can register callbacks to be notified of pressure changes.
Pressure levels: - normal`: Full caching, all features enabled - `elevated`: Reduce cache sizes, flush more often - `critical`: Pause non-essential operations, aggressive cleanup Usage: ``` %% Start monitoring reckon_db_memory:start_link(). %% Check current level normal = reckon_db_memory:level(). %% Register callback reckon_db_memory:on_pressure_change(fun(Level) -> logger:info("Memory pressure: ~p", [Level]) end).''
Summary
Functions
Force an immediate memory check.
Update configuration.
Get current configuration.
Get current memory statistics.
Get current memory pressure level.
Get pressure level for a given memory usage ratio. This is a pure function useful for testing.
Register callback for pressure level changes. Returns a reference that can be used to remove the callback.
Remove a registered callback.
Start the memory monitor with default configuration.
Start the memory monitor with custom configuration.
Types
-type callback_fun() :: fun((pressure_level()) -> any()).
-type callback_ref() :: reference().
-type config() :: #{elevated_threshold => float(), critical_threshold => float(), check_interval => pos_integer()}.
-type pressure_level() :: normal | elevated | critical.
Functions
-spec check_now() -> pressure_level().
Force an immediate memory check.
-spec configure(config()) -> ok.
Update configuration.
-spec get_config() -> config().
Get current configuration.
-spec get_stats() -> map().
Get current memory statistics.
-spec level() -> pressure_level().
Get current memory pressure level.
-spec level(float()) -> pressure_level().
Get pressure level for a given memory usage ratio. This is a pure function useful for testing.
-spec on_pressure_change(callback_fun()) -> callback_ref().
Register callback for pressure level changes. Returns a reference that can be used to remove the callback.
-spec remove_callback(callback_ref()) -> ok.
Remove a registered callback.
Start the memory monitor with default configuration.
Start the memory monitor with custom configuration.