diff --git a/Dockerfile b/Dockerfile index 3b49f63..64bc2dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ENV PYTHONUNBUFFERED 1 WORKDIR /app -RUN apk add --no-cache gcc musl-dev python3-dev libffi-dev +RUN apk add --no-cache gcc musl-dev python3-dev libffi-dev openssl-dev COPY ./requirements.txt /app/requirements.txt RUN pip install --no-cache-dir --prefix=/install -r requirements.txt diff --git a/docker-compose.yml b/docker-compose.yml index 2d8f3c8..a9cb68a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,10 @@ services: - /etc/letsencrypt/live/diningfee.iiti.ac.in/privkey.pem:/etc/letsencrypt/live/diningfee.iiti.ac.in/privkey.pem env_file: - ./.env + environment: + - GUNICORN_WORKERS=9 + - GUNICORN_THREADS=4 + - GUNICORN_TIMEOUT=300 nginx: build: ./nginx diff --git a/entrypoint.sh b/entrypoint.sh index 07591a0..17ffb4e 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,4 +8,15 @@ python manage.py migrate --noinput python manage.py collectstatic --noinput # Start server -gunicorn messWebsite.wsgi:application --bind 0.0.0.0:8000 --workers=16 --preload --timeout 300 +# Counts are env-tunable (see docker-compose.yml). gthread + --max-requests keep +# memory bounded; the previous 16 sync workers were OOM-killed under load. +gunicorn messWebsite.wsgi:application \ + --bind 0.0.0.0:8000 \ + --worker-class=gthread \ + --workers="${GUNICORN_WORKERS:-3}" \ + --threads="${GUNICORN_THREADS:-4}" \ + --timeout="${GUNICORN_TIMEOUT:-300}" \ + --graceful-timeout=30 \ + --max-requests=1000 \ + --max-requests-jitter=100 \ + --preload diff --git a/messWebsite/settings.py b/messWebsite/settings.py index fa911c4..9ec7a60 100644 --- a/messWebsite/settings.py +++ b/messWebsite/settings.py @@ -98,9 +98,14 @@ "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": BASE_DIR / "db.sqlite3", + "OPTIONS": { + # Wait up to 30s for the write lock instead of failing fast with + # "database is locked" under concurrent writes. + "timeout": 30, + "transaction_mode": "IMMEDIATE", + }, } } -DATABASE_OPTIONS = {"timeout": 30} # DATABASES = { diff --git a/requirements.txt b/requirements.txt index 4b20341..c237474 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,3 +15,4 @@ django-cloudinary-storage==0.3.0 gunicorn==23.0.0 whitenoise==6.4.0 django-cors-headers==4.7.0 +PyJWT[crypto]==2.10.1