Skip to content

Commit 149c0e0

Browse files
authored
Merge pull request #1599 from maykinmedia/more-uwsgi-tweaks
2 parents c1139a3 + 1dba1f5 commit 149c0e0

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

bin/docker_start.sh

+22-30
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,38 @@ export UWSGI_CHDIR="src"
2626
export UWSGI_STATIC_MAP="/static=/app/static /media=/app/media"
2727

2828
# --- Process Management
29-
export UWSGI_MASTER=true
29+
# Allow for better worker coordination and graceful shutdowns for unresponsive workers
30+
export UWSGI_MASTER=1
3031
export UWSGI_PROCESSES=${UWSGI_PROCESSES:-4}
3132
export UWSGI_THREADS=${UWSGI_THREADS:-8}
3233

33-
# Shutdown gracefully on SIGTERM (common with supervisord and k8s)
34-
export UWSGI_DIE_ON_TERM=true
34+
# Shutdown gracefully on SIGTERM, which is used by both Docker and k8s to stop containers
35+
export UWSGI_DIE_ON_TERM=1
3536

36-
# We're not hosting multiple apps, so no isolation required
37-
export UWSGI_SINGLE_INTERPRETER=true
37+
# We're not hosting multiple apps, so no interpreter isolation should be required
38+
export UWSGI_SINGLE_INTERPRETER=1
3839

39-
# Enable Python threading
40-
export UWSGI_ENABLE_THREADS=true
40+
# Enable Python threading support
41+
export UWSGI_ENABLE_THREADS=1
4142

42-
# --- HTTP Server Settings
43+
# --- HTTP Settings
44+
# Use http rather than wsgi protocol (also note that UWSGI_PORT is not a native uwsgi option).
4345
export UWSGI_HTTP=${UWSGI_PORT:-8000}
46+
export UWSGI_HTTP_KEEPALIVE=${UWSGI_HTTP_KEEPALIVE:-1}
4447
export UWSGI_HTTP_TIMEOUT=${UWSGI_HTTP_TIMEOUT:-120}
45-
export UWSGI_HTTP_KEEPALIVE=true
48+
49+
# Hard-kill requests after 125 seconds (slightly longer than the default timeout)
50+
export UWSGI_HARAKIRI=${UWSGI_HARAKIRI:-125}
51+
52+
# Periodically recycle workers
53+
export UWSGI_MAX_REQUESTS=${UWSGI_MAX_REQUESTS:-100}
4654

4755
# --- Request Handling
48-
# Buffer size for POST requests
49-
export UWSGI_POST_BUFFERING=8192
50-
51-
# Internal buffer size
52-
export UWSGI_BUFFER_SIZE=65535
53-
54-
# --- Worker Lifecycle
55-
# Make UWSGI_MAX_REQUESTS explicitly opt-in
56-
if [ -n "${UWSGI_MAX_REQUESTS+x}" ]; then
57-
if [ "$UWSGI_MAX_REQUESTS" -gt 1 ] 2>/dev/null; then
58-
export UWSGI_MAX_REQUESTS
59-
else
60-
echo "Warning: UWSGI_MAX_REQUESTS must be greater than 1. The variable will be unset."
61-
unset UWSGI_MAX_REQUESTS
62-
fi
63-
else
64-
unset UWSGI_MAX_REQUESTS
65-
fi
66-
67-
# Hard-kill requests after 60 seconds
68-
export UWSGI_HARAKIRI=${UWSGI_HARAKIRI:-60}
56+
# Buffer size for POST requests (in bytes)
57+
export UWSGI_POST_BUFFERING=${UWSGI_POST_BUFFERING:-8192}
58+
59+
# Internal buffer size (in bytes)
60+
export UWSGI_BUFFER_SIZE=${UWSGI_BUFFER_SIZE:-65535}
6961

7062
# Start Server
7163
>&2 echo "Starting server"

docker-compose.yml

+10
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ services:
8383
- DISABLE_2FA=${DISABLE_2FA:-True}
8484
- DEBUG=True
8585
- IS_HTTPS=no
86+
# Overridable uwsgi settings
87+
- UWSGI_PROCESSES
88+
- UWSGI_THREADS
89+
- UWSGI_PORT
90+
- UWSGI_HTTP_KEEPALIVE
91+
- UWSGI_HTTP_TIMEOUT
92+
- UWSGI_HARAKIRI
93+
- UWSGI_MAX_REQUESTS
94+
- UWSGI_POST_BUFFERING
95+
- UWSGI_BUFFER_SIZE
8696
healthcheck:
8797
test: ["CMD", "python", "-c", "import requests; exit(requests.head('http://localhost:8000/admin/').status_code not in [200, 302])"]
8898
interval: 30s

0 commit comments

Comments
 (0)