From 88cd9aedb7c1dce0b667b12e296cb824e084f8be Mon Sep 17 00:00:00 2001 From: kelvintsim <83445753+kelvintsim@users.noreply.github.com> Date: Tue, 13 May 2025 10:28:13 +0800 Subject: [PATCH] add gunicorn keepalive setting (#19537) Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: Bowen Liang --- api/docker/entrypoint.sh | 1 + docker/.env.example | 3 +++ docker/docker-compose.yaml | 1 + 3 files changed, 5 insertions(+) diff --git a/api/docker/entrypoint.sh b/api/docker/entrypoint.sh index 68f3c65a4b..b2bbcaf1d6 100755 --- a/api/docker/entrypoint.sh +++ b/api/docker/entrypoint.sh @@ -35,6 +35,7 @@ else --worker-class ${SERVER_WORKER_CLASS:-gevent} \ --worker-connections ${SERVER_WORKER_CONNECTIONS:-10} \ --timeout ${GUNICORN_TIMEOUT:-200} \ + --keep-alive ${GUNICORN_KEEP_ALIVE:-2} \ app:app fi fi diff --git a/docker/.env.example b/docker/.env.example index 0faf9a337d..de612b9be9 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -142,6 +142,9 @@ CELERY_WORKER_CLASS= # it is recommended to set it to 360 to support a longer sse connection time. GUNICORN_TIMEOUT=360 +# The number of seconds to wait for requests on a Keep-Alive connection, default to 2 +GUNICORN_KEEP_ALIVE=2 + # The number of Celery workers. The default is 1, and can be set as needed. CELERY_WORKER_AMOUNT= diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 72a42c9841..d107492fdf 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -37,6 +37,7 @@ x-shared-env: &shared-api-worker-env SERVER_WORKER_CONNECTIONS: ${SERVER_WORKER_CONNECTIONS:-10} CELERY_WORKER_CLASS: ${CELERY_WORKER_CLASS:-} GUNICORN_TIMEOUT: ${GUNICORN_TIMEOUT:-360} + GUNICORN_KEEP_ALIVE: ${GUNICORN_KEEP_ALIVE:-2} CELERY_WORKER_AMOUNT: ${CELERY_WORKER_AMOUNT:-} CELERY_AUTO_SCALE: ${CELERY_AUTO_SCALE:-false} CELERY_MAX_WORKERS: ${CELERY_MAX_WORKERS:-}