diff --git a/.env.example b/.env.example index 2ff06669..b8654efc 100644 --- a/.env.example +++ b/.env.example @@ -23,6 +23,9 @@ SQL_PORT=5432 # Gunicorn WEB_CONCURRENCY=4 +# Threads per web worker. Each worker is a full copy of the app in memory; threads share it. +# For low traffic, WEB_CONCURRENCY=1 with WEB_THREADS=4 uses far less memory. +WEB_THREADS=1 # App Configs # Enable this if you want to keep deleted transactions in the database diff --git a/README.md b/README.md index 9f7ad5ea..66eed081 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,8 @@ To create the first user, open the container's console using Unraid's UI, by cli | ENABLE_SOFT_DELETE | true\|false | false | Whether to enable transactions soft delete, if enabled, deleted transactions will remain in the database. Useful for imports and avoiding duplicate entries. | | KEEP_DELETED_TRANSACTIONS_FOR | int | 365 | Time in days to keep soft deleted transactions for. If 0, will keep all transactions indefinitely. Only works if ENABLE_SOFT_DELETE is true. | | TASK_WORKERS | int | 1 | How many workers to have for async tasks. One should be enough for most use cases | +| WEB_CONCURRENCY | int | 1 | How many web worker processes to run. Each one is a full copy of the app in memory | +| WEB_THREADS | int | 1 | How many threads each web worker runs. Threads share their worker's memory, so `WEB_CONCURRENCY=1` with `WEB_THREADS=4` serves more requests at once with less RAM than 2 workers | | IMPORT_TEMP_ROOT | string | /usr/src/app/temp | Where uploaded import files wait to be processed. Defaults to the `temp` folder inside the app folder. Must be writable and shared between the web and task processes. | | CACHE_ROOT | string | /var/tmp | The writable folder the file-based caches are stored in. | | DEMO | true\|false | false | If demo mode is enabled. | diff --git a/docker/prod/django/start b/docker/prod/django/start index bbd7caae..f197e32e 100644 --- a/docker/prod/django/start +++ b/docker/prod/django/start @@ -21,4 +21,5 @@ python manage.py setup_oauth # Check for updates on startup instead of waiting for the next periodic run; never block boot on it python manage.py procrastinate defer check_for_updates || true -exec gunicorn WYGIWYH.wsgi:application --bind 0.0.0.0:$INTERNAL_PORT --timeout 600 +# Only pass --threads when WEB_THREADS is set, so a --threads in GUNICORN_CMD_ARGS still applies otherwise +exec gunicorn WYGIWYH.wsgi:application --bind 0.0.0.0:$INTERNAL_PORT --timeout 600 ${WEB_THREADS:+--threads "$WEB_THREADS"}