diff --git a/Dockerfile.ecs b/Dockerfile.ecs index 57a82608..26c8db24 100644 --- a/Dockerfile.ecs +++ b/Dockerfile.ecs @@ -32,6 +32,10 @@ COPY . . # Set Python path ENV PYTHONPATH="${PYTHONPATH}:/app/ai_ta_backend" +# Sensible defaults for worker recycling; override via task env if needed +ENV GUNICORN_MAX_REQUESTS=1000 +ENV GUNICORN_MAX_REQUESTS_JITTER=200 + # Expose port EXPOSE 8001 @@ -40,4 +44,4 @@ HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \ CMD curl -f http://localhost:8001/health || exit 1 # Run the application -CMD ["gunicorn", "--workers=2", "--threads=3", "--worker-class=gthread", "ai_ta_backend.main:app", "--timeout=1800", "--bind=0.0.0.0:8001"] +CMD ["gunicorn", "--workers=2", "--threads=3", "--worker-class=gthread", "ai_ta_backend.main:app", "--timeout=1800", "--bind=0.0.0.0:8001", "--max-requests", "${GUNICORN_MAX_REQUESTS}", "--max-requests-jitter", "${GUNICORN_MAX_REQUESTS_JITTER}"] diff --git a/Self-Hosted-Dockerfile b/Self-Hosted-Dockerfile index 98ba2106..d9e2a6ac 100644 --- a/Self-Hosted-Dockerfile +++ b/Self-Hosted-Dockerfile @@ -31,8 +31,12 @@ COPY . . # Set the Python path to include the ai_ta_backend directory ENV PYTHONPATH="${PYTHONPATH}:/usr/src/app/ai_ta_backend" +# Sensible defaults for worker recycling; override at runtime if desired +ENV GUNICORN_MAX_REQUESTS=1000 +ENV GUNICORN_MAX_REQUESTS_JITTER=200 + # Make port 8001 available to the world outside this container EXPOSE 8001 # Run the application using Gunicorn with specified configuration -CMD ["gunicorn", "--workers=2", "--threads=3", "--worker-class=gthread", "ai_ta_backend.main:app", "--timeout=1800", "--bind=0.0.0.0:8001"] +CMD ["gunicorn", "--workers=2", "--threads=3", "--worker-class=gthread", "ai_ta_backend.main:app", "--timeout=1800", "--bind=0.0.0.0:8001", "--max-requests", "${GUNICORN_MAX_REQUESTS}", "--max-requests-jitter", "${GUNICORN_MAX_REQUESTS_JITTER}"]