Skip to content

Commit 7b0df86

Browse files
liqiang-fit2cloudliuruibin
authored andcommitted
perf: revert preload.
1 parent 8d3ee5d commit 7b0df86

File tree

6 files changed

+40
-5
lines changed

6 files changed

+40
-5
lines changed

apps/common/management/commands/services/services/gunicorn.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def cmd(self):
1919
cmd = [
2020
'gunicorn', 'maxkb.wsgi:application',
2121
'-b', bind,
22-
'--preload',
2322
'-k', 'gthread',
2423
'--threads', '200',
2524
'-w', str(self.worker),

apps/common/management/commands/services/services/local_model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def cmd(self):
2929
cmd = [
3030
'gunicorn', 'maxkb.wsgi:application',
3131
'-b', bind,
32-
'--preload',
3332
'-k', 'gthread',
3433
'--threads', '200',
3534
'-w', str(worker),

apps/common/management/commands/services/services/scheduler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def cmd(self):
2121
cmd = [
2222
'gunicorn', 'maxkb.wsgi:application',
2323
'-b', bind,
24-
'--preload',
2524
'-k', 'gthread',
2625
'--threads', '200',
2726
'-w', str(self.worker),

apps/maxkb/settings/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
from .base import *
1010
from .logging import *
1111
from .auth import *
12-
from .lib import *
12+
from .lib import *
13+
from .mem import *

apps/maxkb/settings/mem.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# coding=utf-8
2+
import os
3+
import gc
4+
import threading
5+
from maxkb.const import CONFIG
6+
from common.utils.logger import maxkb_logger
7+
import tracemalloc
8+
9+
CURRENT_PID=os.getpid()
10+
GC_THRESHOLD = (100, 5, 5)
11+
# 1 hour
12+
GC_INTERVAL = 3600
13+
14+
def change_gc_threshold():
15+
old_threshold = gc.get_threshold()
16+
gc.set_threshold(*GC_THRESHOLD)
17+
maxkb_logger.debug(f"(PID: {CURRENT_PID}) GC thresholds changed from {old_threshold}{GC_THRESHOLD}")
18+
19+
20+
def 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)
26+
collected = gc.collect()
27+
maxkb_logger.debug(f"(PID: {CURRENT_PID}) Forced GC ({collected} objects collected)")
28+
threading.Timer(GC_INTERVAL, force_gc).start()
29+
30+
31+
def init_memory_optimization():
32+
tracemalloc.start()
33+
change_gc_threshold()
34+
force_gc()
35+
maxkb_logger.debug("(PID: {CURRENT_PID}) Memory optimization (GC tuning) started.")
36+
37+
if CONFIG.get("ENABLE_MEMORY_OPTIMIZATION", '1') == "1":
38+
init_memory_optimization()

installer/Dockerfile-base

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
3131
chmod g+xr /usr/bin/ld.so && \
3232
chmod g+x /usr/local/bin/python* && \
3333
apt-get clean all && \
34-
echo "/usr/lib/$(uname -m)-linux-gnu/libjemalloc.so.2" > /etc/ld.so.preload && \
3534
rm -rf /var/lib/apt/lists/* /usr/share/doc/* /usr/share/man/* /usr/share/info/* /usr/share/locale/* /usr/share/lintian/* /usr/share/linda/* /var/cache/* /var/log/* /var/tmp/* /tmp/*
3635
COPY --from=vector-model --chmod=700 /opt/maxkb-app/model /opt/maxkb-app/model
3736

0 commit comments

Comments
 (0)