File tree Expand file tree Collapse file tree 1 file changed +1
-10
lines changed
Expand file tree Collapse file tree 1 file changed +1
-10
lines changed Original file line number Diff line number Diff line change 44import threading
55from maxkb .const import CONFIG
66from common .utils .logger import maxkb_logger
7- import tracemalloc
87
98CURRENT_PID = os .getpid ()
109GC_THRESHOLD = (100 , 5 , 5 )
@@ -16,23 +15,15 @@ def change_gc_threshold():
1615 gc .set_threshold (* GC_THRESHOLD )
1716 maxkb_logger .debug (f"(PID: { CURRENT_PID } ) GC thresholds changed from { old_threshold } → { GC_THRESHOLD } " )
1817
19-
2018def force_gc ():
21- snapshot = tracemalloc .take_snapshot ()
22- top_stats = snapshot .statistics ('lineno' )
23- maxkb_logger .debug ("[ Top 10 memory-consuming lines ]" )
24- for stat in top_stats [:10 ]:
25- maxkb_logger .debug (stat )
2619 collected = gc .collect ()
2720 maxkb_logger .debug (f"(PID: { CURRENT_PID } ) Forced GC ({ collected } objects collected)" )
2821 threading .Timer (GC_INTERVAL , force_gc ).start ()
2922
30-
3123def init_memory_optimization ():
32- tracemalloc .start ()
3324 change_gc_threshold ()
3425 force_gc ()
3526 maxkb_logger .debug ("(PID: {CURRENT_PID}) Memory optimization (GC tuning) started." )
3627
37- if CONFIG .get ("ENABLE_MEMORY_OPTIMIZATION" , '0 ' ) == "1" :
28+ if CONFIG .get ("ENABLE_MEMORY_OPTIMIZATION" , '1 ' ) == "1" :
3829 init_memory_optimization ()
You can’t perform that action at this time.
0 commit comments