Skip to main content

Module memory_guard

Module memory_guard 

Source
Expand description

Memory guard: checks RAM availability before loading the ONNX model. Memory guard: checks RAM availability before loading the ONNX model.

Loading the model via fastembed consumes approximately crate::constants::EMBEDDING_LOAD_EXPECTED_RSS_MB MiB of resident memory. Without this guard, multiple parallel invocations can exhaust RAM and trigger OOM (Out-Of-Memory), stalling the system.

This guard queries the OS via sysinfo before any heavy initialisation, aborting with crate::errors::AppError::LowMemory (exit 77) when the configured floor is not met.

Functionsยง

available_memory_mb
Returns the current available memory in MiB.
calculate_safe_concurrency
Calculates the safe concurrency ceiling for heavy embedding workloads.
check_available_memory
Checks whether sufficient memory is available to start loading the model.
current_process_memory_mb
Returns the current process RSS in MiB when available.