Skip to content

Commit e1b171b

Browse files
authored
fix OOM kills by reducing worker counts, cuts memory utilization (#406)
1 parent a31a0d2 commit e1b171b

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
6161
apt-get update && apt-get install -y --no-install-recommends \
6262
libpq5 \
6363
curl \
64-
wget \
6564
&& apt-get upgrade -y
6665

6766
# Create non-root user for security
@@ -110,7 +109,6 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
110109
apt-get update && apt-get install -y --no-install-recommends \
111110
libpq5 \
112111
curl \
113-
wget \
114112
&& apt-get upgrade -y
115113

116114
# Create non-root user for security
@@ -121,7 +119,8 @@ RUN groupadd -r appuser && \
121119
ENV PYTHONUNBUFFERED=1 \
122120
PYTHONPATH=/app/src \
123121
PATH="/app/.venv/bin:$PATH" \
124-
VIRTUAL_ENV=/app/.venv
122+
VIRTUAL_ENV=/app/.venv \
123+
DJANGO_Q_WORKERS=1
125124

126125
WORKDIR /app
127126

src/gunicorn_config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,18 @@
6464
# A positive integer. Generally set in the 1-5 seconds range.
6565
#
6666

67-
workers = 3
67+
workers = 1
68+
threads = 2
6869
worker_class = "gthread"
6970
worker_connections = 1000
7071
timeout = 30
7172
keepalive = 2
7273
worker_tmp_dir = "/dev/shm"
7374

75+
# Memory leak mitigation - restart workers after handling N requests
76+
max_requests = 1000
77+
max_requests_jitter = 50
78+
7479
# preload_app - Load application code before forking worker processes.
7580
# This conserves memory and speeds up server boot times by loading
7681
# the Django application once in the main process, then forking

src/settings/components/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
# Django-Q2 configuration (sync mode for testing, use redis/orm in production)
105105
Q_CLUSTER = {
106106
"name": "operationcode",
107-
"workers": 2,
107+
"workers": config("DJANGO_Q_WORKERS", default=1, cast=int),
108108
"timeout": 60,
109109
"retry": 120,
110110
"queue_limit": 50,

0 commit comments

Comments
 (0)