-
Notifications
You must be signed in to change notification settings - Fork 12
feat: configurable web worker count via WEB_WORKERS env var #1145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,5 +11,11 @@ python manage.py migrate | |
| if [ "${DEBUGGER:-0}" = "1" ]; then | ||
| exec python -Xfrozen_modules=off -m debugpy --listen 0.0.0.0:5678 -m uvicorn config.asgi:application --host 0.0.0.0 | ||
| else | ||
| exec uvicorn config.asgi:application --host 0.0.0.0 --reload --reload-include '*.html' | ||
| WORKERS="${WEB_WORKERS:-1}" | ||
| if [ "$WORKERS" -gt 1 ]; then | ||
| # --reload is incompatible with --workers, so skip it for multi-worker mode | ||
| exec uvicorn config.asgi:application --host 0.0.0.0 --workers "$WORKERS" | ||
|
Comment on lines
+14
to
+17
|
||
| else | ||
| exec uvicorn config.asgi:application --host 0.0.0.0 --reload --reload-include '*.html' | ||
| fi | ||
| fi | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,4 +6,6 @@ set -o nounset | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| python /app/manage.py collectstatic --noinput | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| exec newrelic-admin run-program /usr/local/bin/gunicorn config.asgi --bind 0.0.0.0:5000 --chdir=/app -k uvicorn.workers.UvicornWorker | ||||||||||||||||||||||||
| exec newrelic-admin run-program /usr/local/bin/gunicorn config.asgi \ | ||||||||||||||||||||||||
| --workers "${WEB_WORKERS:-4}" \ | ||||||||||||||||||||||||
|
Comment on lines
+9
to
+10
|
||||||||||||||||||||||||
| exec newrelic-admin run-program /usr/local/bin/gunicorn config.asgi \ | |
| --workers "${WEB_WORKERS:-4}" \ | |
| # Validate WEB_WORKERS as a positive integer, defaulting to 4 if unset or invalid | |
| WEB_WORKERS_VALUE="${WEB_WORKERS:-4}" | |
| if ! [[ "${WEB_WORKERS_VALUE}" =~ ^[1-9][0-9]*$ ]]; then | |
| echo "Invalid WEB_WORKERS value '${WEB_WORKERS:-unset}'. Must be a positive integer. Falling back to 4." >&2 | |
| WEB_WORKERS_VALUE=4 | |
| fi | |
| exec newrelic-admin run-program /usr/local/bin/gunicorn config.asgi \ | |
| --workers "${WEB_WORKERS_VALUE}" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The numeric comparison on line 15 will fail with a cryptic error if WEB_WORKERS is set to a non-numeric value (e.g., WEB_WORKERS=abc). Consider adding input validation before the comparison to ensure WORKERS is a positive integer, or use a more defensive comparison that handles non-numeric values gracefully.