Skip to content

Commit

Permalink
chore: update uwsgi configuration
Browse files Browse the repository at this point in the history
Allows controlling amount of uwsgi processes using
environment variables.

Also copies some good configuration from other projects.

Refs: HP-2134
  • Loading branch information
charn committed Jan 8, 2024
1 parent ee8c4e6 commit 94a090d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
28 changes: 25 additions & 3 deletions .prod/uwsgi.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[uwsgi]
# https://uwsgi-docs.readthedocs.io/en/latest/Options.html
http-socket = :8000
chdir = /app
mount = $(APP_URL_PATH)=tunnistamo/wsgi.py
Expand All @@ -7,7 +8,28 @@ static-map = $(MEDIA_URL_ROOTLESS)=$(MEDIA_ROOT)
static-map = $(STATIC_URL_ROOTLESS)=$(STATIC_ROOT)
uid = appuser
gid = appuser
enable-threads = true
master = true
processes = $(UWSGI_PROCESSES)
threads = $(UWSGI_THREADS)

# by default uwsgi reloads on SIGTERM instead of terminating
# this makes container slow to stop, so we change it here
die-on-term = true
harakiri = 20
harakiri-graceful-timeout = 5
# Default listen queue is 100
harakiri-queue-threshold = 80
buffer-size = 32768
master = 1
processes = 2
threads = 2

# Reload workers regularly to keep memory fresh
# and ease potential memory leaks
max-requests = 1000 # Restart workers after this many requests
reload-on-rss = 300 # Restart workers after this much resident memory
worker-reload-mercy = 60 # How long to wait before forcefully killing workers (default is 60)

# Suppress errors about clients closing sockets, happens with nginx as the ingress when
# http pipes are closed before workers has had the time to serve content to the pipe
ignore-sigpipe = true
ignore-write-errors = true
disable-write-exception = true
3 changes: 3 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ if [[ ! -z "$@" ]]; then
elif [[ "$DEV_SERVER" = "1" ]]; then
python ./manage.py runserver 0.0.0.0:8000
else
export UWSGI_THREADS=${UWSGI_THREADS:-1}
export UWSGI_PROCESSES=${UWSGI_PROCESSES:-4}

# We want to have a *_URL environment variables configure
# both Django static/media files URL generation
# and the corresponding file serving in uWSGI.
Expand Down

0 comments on commit 94a090d

Please sign in to comment.