File tree Expand file tree Collapse file tree 1 file changed +3
-13
lines changed
Expand file tree Collapse file tree 1 file changed +3
-13
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 random
78
89CURRENT_PID = os .getpid ()
9- GC_THRESHOLD = (100 , 5 , 5 )
1010# 1 hour
1111GC_INTERVAL = 3600
1212
13- def change_gc_threshold ():
14- old_threshold = gc .get_threshold ()
15- gc .set_threshold (* GC_THRESHOLD )
16- maxkb_logger .debug (f"(PID: { CURRENT_PID } ) GC thresholds changed from { old_threshold } → { GC_THRESHOLD } " )
17-
1813def force_gc ():
1914 collected = gc .collect ()
2015 maxkb_logger .debug (f"(PID: { CURRENT_PID } ) Forced GC ({ collected } objects collected)" )
21- threading .Timer (GC_INTERVAL , force_gc ).start ()
22-
23- def init_memory_optimization ():
24- change_gc_threshold ()
25- force_gc ()
26- maxkb_logger .debug ("(PID: {CURRENT_PID}) Memory optimization (GC tuning) started." )
16+ threading .Timer (GC_INTERVAL - random .randint (0 , 900 , force_gc ).start ()
2717
2818if CONFIG .get ("ENABLE_MEMORY_OPTIMIZATION" , '1' ) == "1" :
29- init_memory_optimization ()
19+ threading . Timer ( GC_INTERVAL - random . randint ( 0 , 900 ), force_gc ). start ()
You can’t perform that action at this time.
0 commit comments