perf: revert preload.
parent
792d32d7e1
commit
ab170c843e
|
|
@ -4,26 +4,16 @@ import gc
|
||||||
import threading
|
import threading
|
||||||
from maxkb.const import CONFIG
|
from maxkb.const import CONFIG
|
||||||
from common.utils.logger import maxkb_logger
|
from common.utils.logger import maxkb_logger
|
||||||
|
import random
|
||||||
|
|
||||||
CURRENT_PID=os.getpid()
|
CURRENT_PID=os.getpid()
|
||||||
GC_THRESHOLD = (100, 5, 5)
|
|
||||||
# 1 hour
|
# 1 hour
|
||||||
GC_INTERVAL = 3600
|
GC_INTERVAL = 3600
|
||||||
|
|
||||||
def change_gc_threshold():
|
|
||||||
old_threshold = gc.get_threshold()
|
|
||||||
gc.set_threshold(*GC_THRESHOLD)
|
|
||||||
maxkb_logger.debug(f"(PID: {CURRENT_PID}) GC thresholds changed from {old_threshold} → {GC_THRESHOLD}")
|
|
||||||
|
|
||||||
def force_gc():
|
def force_gc():
|
||||||
collected = gc.collect()
|
collected = gc.collect()
|
||||||
maxkb_logger.debug(f"(PID: {CURRENT_PID}) Forced GC ({collected} objects collected)")
|
maxkb_logger.debug(f"(PID: {CURRENT_PID}) Forced GC ({collected} objects collected)")
|
||||||
threading.Timer(GC_INTERVAL, force_gc).start()
|
threading.Timer(GC_INTERVAL - random.randint(0, 900, force_gc).start()
|
||||||
|
|
||||||
def init_memory_optimization():
|
|
||||||
change_gc_threshold()
|
|
||||||
force_gc()
|
|
||||||
maxkb_logger.debug("(PID: {CURRENT_PID}) Memory optimization (GC tuning) started.")
|
|
||||||
|
|
||||||
if CONFIG.get("ENABLE_MEMORY_OPTIMIZATION", '1') == "1":
|
if CONFIG.get("ENABLE_MEMORY_OPTIMIZATION", '1') == "1":
|
||||||
init_memory_optimization()
|
threading.Timer(GC_INTERVAL - random.randint(0, 900), force_gc).start()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue