Skip to content

Commit f7bf962

Browse files
Chore: Fix worker OOM sigkill and add timeout of 30s instead of default 5s (#149)
1 parent 4390026 commit f7bf962

5 files changed

Lines changed: 24 additions & 3 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ENV PYTHONUNBUFFERED 1
44

55
WORKDIR /app
66

7-
RUN apk add --no-cache gcc musl-dev python3-dev libffi-dev
7+
RUN apk add --no-cache gcc musl-dev python3-dev libffi-dev openssl-dev
88

99
COPY ./requirements.txt /app/requirements.txt
1010
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ services:
1212
- /etc/letsencrypt/live/diningfee.iiti.ac.in/privkey.pem:/etc/letsencrypt/live/diningfee.iiti.ac.in/privkey.pem
1313
env_file:
1414
- ./.env
15+
environment:
16+
- GUNICORN_WORKERS=9
17+
- GUNICORN_THREADS=4
18+
- GUNICORN_TIMEOUT=300
1519

1620
nginx:
1721
build: ./nginx

entrypoint.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,15 @@ python manage.py migrate --noinput
88
python manage.py collectstatic --noinput
99

1010
# Start server
11-
gunicorn messWebsite.wsgi:application --bind 0.0.0.0:8000 --workers=16 --preload --timeout 300
11+
# Counts are env-tunable (see docker-compose.yml). gthread + --max-requests keep
12+
# memory bounded; the previous 16 sync workers were OOM-killed under load.
13+
gunicorn messWebsite.wsgi:application \
14+
--bind 0.0.0.0:8000 \
15+
--worker-class=gthread \
16+
--workers="${GUNICORN_WORKERS:-3}" \
17+
--threads="${GUNICORN_THREADS:-4}" \
18+
--timeout="${GUNICORN_TIMEOUT:-300}" \
19+
--graceful-timeout=30 \
20+
--max-requests=1000 \
21+
--max-requests-jitter=100 \
22+
--preload

messWebsite/settings.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,14 @@
9898
"default": {
9999
"ENGINE": "django.db.backends.sqlite3",
100100
"NAME": BASE_DIR / "db.sqlite3",
101+
"OPTIONS": {
102+
# Wait up to 30s for the write lock instead of failing fast with
103+
# "database is locked" under concurrent writes.
104+
"timeout": 30,
105+
"transaction_mode": "IMMEDIATE",
106+
},
101107
}
102108
}
103-
DATABASE_OPTIONS = {"timeout": 30}
104109

105110

106111
# DATABASES = {

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ django-cloudinary-storage==0.3.0
1515
gunicorn==23.0.0
1616
whitenoise==6.4.0
1717
django-cors-headers==4.7.0
18+
PyJWT[crypto]==2.10.1

0 commit comments

Comments
 (0)