SIENTIAPDE-1231

Add memory management function to model_repository.py

- Introduced `force_memory_release` function to enhance memory management by triggering garbage collection and attempting to release unused memory.
- Utilized `ctypes` to call `malloc_trim` for further memory optimization, improving overall performance during model operations.
This commit is contained in:
vitor-aignosi
2025-10-13 15:50:37 -03:00
parent 331df2dd18
commit 143dd7759e

View File

@@ -29,12 +29,22 @@ from numpy import ndarray
from typing import Any
import gc
from sientia_do.temporal.constants import DATETIME_FORMAT_WITH_TZ
import ctypes
ARTIFACTS_PATH = "./tmp/artifacts"
TRANSFORMED_COMPRESSED_PATH = "artifacts/training_transformer.pkl"
PREDICTION_COMPRESSED_PATH = "artifacts/stacking_model.pkl"
def force_memory_release():
gc.collect()
try:
ctypes.CDLL("libc.so.6").malloc_trim(0)
except:
pass
class MLFlowRepository():
def __init__(self, host: str, username: str, password: str, logger: Logger):