perf: revert preload.
parent
dc9c4c9e01
commit
792d32d7e1
|
|
@ -4,7 +4,6 @@ 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 tracemalloc
|
|
||||||
|
|
||||||
CURRENT_PID=os.getpid()
|
CURRENT_PID=os.getpid()
|
||||||
GC_THRESHOLD = (100, 5, 5)
|
GC_THRESHOLD = (100, 5, 5)
|
||||||
|
|
@ -16,23 +15,15 @@ def change_gc_threshold():
|
||||||
gc.set_threshold(*GC_THRESHOLD)
|
gc.set_threshold(*GC_THRESHOLD)
|
||||||
maxkb_logger.debug(f"(PID: {CURRENT_PID}) GC thresholds changed from {old_threshold} → {GC_THRESHOLD}")
|
maxkb_logger.debug(f"(PID: {CURRENT_PID}) GC thresholds changed from {old_threshold} → {GC_THRESHOLD}")
|
||||||
|
|
||||||
|
|
||||||
def force_gc():
|
def force_gc():
|
||||||
snapshot = tracemalloc.take_snapshot()
|
|
||||||
top_stats = snapshot.statistics('lineno')
|
|
||||||
maxkb_logger.debug("[ Top 10 memory-consuming lines ]")
|
|
||||||
for stat in top_stats[:10]:
|
|
||||||
maxkb_logger.debug(stat)
|
|
||||||
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, force_gc).start()
|
||||||
|
|
||||||
|
|
||||||
def init_memory_optimization():
|
def init_memory_optimization():
|
||||||
tracemalloc.start()
|
|
||||||
change_gc_threshold()
|
change_gc_threshold()
|
||||||
force_gc()
|
force_gc()
|
||||||
maxkb_logger.debug("(PID: {CURRENT_PID}) Memory optimization (GC tuning) started.")
|
maxkb_logger.debug("(PID: {CURRENT_PID}) Memory optimization (GC tuning) started.")
|
||||||
|
|
||||||
if CONFIG.get("ENABLE_MEMORY_OPTIMIZATION", '0') == "1":
|
if CONFIG.get("ENABLE_MEMORY_OPTIMIZATION", '1') == "1":
|
||||||
init_memory_optimization()
|
init_memory_optimization()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue