From 410036759e15960d1f4d337957fb0630922f956f Mon Sep 17 00:00:00 2001 From: Mathijs de Bruin Date: Sun, 11 May 2025 12:21:01 +0100 Subject: [PATCH] Configurable worker count. Closes #1668. --- docker-compose.yml | 1 + start.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 9c460d99..d097eb4e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,6 +34,7 @@ services: - WO_DEV - WO_DEV_WATCH_PLUGINS - WO_SECRET_KEY + - WEB_CONCURRENCY restart: unless-stopped oom_score_adj: 0 broker: diff --git a/start.sh b/start.sh index 4c8763d2..6807f347 100755 --- a/start.sh +++ b/start.sh @@ -144,6 +144,18 @@ else conf="nginx-ssl.conf" fi + # Only set if `WEB_CONCURRENCY` is not defined, allows overriding. + # See: https://docs.gunicorn.org/en/latest/settings.html#workers + if [ -z "$WEB_CONCURRENCY" ]; then + # Default gunicorn worker count to 2 x availabe cores + 1 + # nproc gives _available_ (rather than physicall present) CPU cores. + CPU_COUNT=$(nproc) + export WEB_CONCURRENCY=$((2*$CPU_COUNT+1)) + echo "Setting WEB_CONCURRENCY based on $CPU_COUNT available CPU cores to start $WEB_CONCURRENCY gunicorn workers." + else + echo "Using pre-defined WEB_CONCURRENCY override to start $WEB_CONCURRENCY gunicorn workers." + fi + congrats nginx -c $(pwd)/nginx/$conf