File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change 55from maxkb .const import CONFIG
66from common .utils .logger import maxkb_logger
77import random
8+ import psutil
89
910CURRENT_PID = os .getpid ()
1011# 1 hour
1112GC_INTERVAL = 3600
1213
1314def enable_force_gc ():
15+ before = int (psutil .Process (CURRENT_PID ).memory_info ().rss / 1024 / 1024 )
1416 collected = gc .collect ()
15- maxkb_logger .debug (f"(PID: { CURRENT_PID } ) Forced GC ({ collected } objects collected)" )
17+ try :
18+ import ctypes
19+ ctypes .CDLL ("libc.so.6" ).malloc_trim (0 )
20+ except Exception :
21+ pass
22+ after = int (psutil .Process (CURRENT_PID ).memory_info ().rss / 1024 / 1024 )
23+ maxkb_logger .debug (f"(PID: { CURRENT_PID } ) Forced GC ({ collected } objects and { before - after } MB recycled)" )
1624 t = threading .Timer (GC_INTERVAL - random .randint (0 , 900 ), enable_force_gc )
1725 t .daemon = True
1826 t .start ()
You can’t perform that action at this time.
0 commit comments