diff --git a/docker/Dockerfile b/docker/Dockerfile index 1b27c173..0aae4353 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -20,7 +20,7 @@ RUN chmod +x /usr/local/bin/docker-entrypoint.sh # GUNICORN_BIND - full bind address (default: [::]:8000, IPv4+IPv6) # GUNICORN_HOST - bind host (default: [::]) # GUNICORN_PORT - bind port (default: 8000) -# GUNICORN_WORKERS - number of workers (default: number of CPUs) +# GUNICORN_WORKERS - number of workers (default: 2 * CPU + 1) # GUNICORN_ARGS - additional arguments (e.g., "--timeout 120") USER gunicorn diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 2ac91149..125716ed 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -15,9 +15,9 @@ if [ "${1:0:1}" = '-' ] || [ -z "${1##*:*}" ]; then set -- --bind "$BIND" "$@" fi - # Add workers if not specified - default to number of CPUs + # Add workers if not specified - default to (2 * CPU_COUNT) + 1 if [[ ! " $* $GUNICORN_ARGS " =~ " --workers " ]] && [[ ! " $* $GUNICORN_ARGS " =~ " -w " ]] && [[ ! "$* $GUNICORN_ARGS" =~ --workers= ]] && [[ ! "$* $GUNICORN_ARGS" =~ -w= ]]; then - WORKERS="${GUNICORN_WORKERS:-$(nproc)}" + WORKERS="${GUNICORN_WORKERS:-$(( 2 * $(nproc) + 1 ))}" set -- --workers "$WORKERS" "$@" fi diff --git a/docs/content/guides/docker.md b/docs/content/guides/docker.md index 0c9d49eb..10470aee 100644 --- a/docs/content/guides/docker.md +++ b/docs/content/guides/docker.md @@ -27,7 +27,7 @@ docker run -p 8000:8000 -v $(pwd):/app ghcr.io/benoitc/gunicorn app:app | `GUNICORN_BIND` | Full bind address | `[::]:8000` (IPv4+IPv6) | | `GUNICORN_HOST` | Bind host | `[::]` | | `GUNICORN_PORT` | Bind port | `8000` | -| `GUNICORN_WORKERS` | Number of workers | Number of CPUs | +| `GUNICORN_WORKERS` | Number of workers | `(2 * CPU) + 1` | | `GUNICORN_ARGS` | Additional arguments | (none) | ### With Configuration