reckon_db_memory (reckon_db v1.2.3)

View Source

Memory 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

callback_fun/0

-type callback_fun() :: fun((pressure_level()) -> any()).

callback_ref/0

-type callback_ref() :: reference().

config/0

-type config() ::
          #{elevated_threshold => float(),
            critical_threshold => float(),
            check_interval => pos_integer()}.

pressure_level/0

-type pressure_level() :: normal | elevated | critical.

Functions

check_now()

-spec check_now() -> pressure_level().

Force an immediate memory check.

code_change(OldVsn, State, Extra)

configure(Config)

-spec configure(config()) -> ok.

Update configuration.

get_config()

-spec get_config() -> config().

Get current configuration.

get_stats()

-spec get_stats() -> map().

Get current memory statistics.

handle_call(Request, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(Config)

level()

-spec level() -> pressure_level().

Get current memory pressure level.

level(UsageRatio)

-spec level(float()) -> pressure_level().

Get pressure level for a given memory usage ratio. This is a pure function useful for testing.

on_pressure_change(Fun)

-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.

remove_callback(Ref)

-spec remove_callback(callback_ref()) -> ok.

Remove a registered callback.

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

Start the memory monitor with default configuration.

start_link(Config)

-spec start_link(config()) -> {ok, pid()} | {error, term()}.

Start the memory monitor with custom configuration.

terminate(Reason, State)