From 9262e9987e22e9a51c4e1c8197a6463759750069 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Fri, 8 Sep 2023 14:23:08 -0400 Subject: [PATCH] More work on configs and env --- .env.default | 12 ++++++++++-- conf/aether_fastapi_gunicorn_conf.py | 10 +++++----- conf/aether_flask_gunicorn_conf.py | 10 +++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.env.default b/.env.default index 677feaf..502a065 100644 --- a/.env.default +++ b/.env.default @@ -93,8 +93,11 @@ AE_SMTP_USERNAME=send_mail AE_API_ENV=development AE_API_DIR=/srv/aether_api AE_API_LOG_PATH="/logs/aether_api.log" -AE_API_WORKERS=2 -AE_API_THREADS=1 +AE_API_GUNICORN_TIMEOUT=2100 # (default=30; should be much higher) +AE_API_GUNICORN_GRACEFUL_TIMEOUT=30 # (default=30) +AE_API_GUNICORN_KEEPALIVE=30 # (default=2) +AE_API_GUNICORN_WORKERS=2 # (default=2) +AE_API_GUNICORN_THREADS=2 # (default=2) AE_API_RELOAD=False AE_API_JWT_KEY="ABC123 22 CHARS" # 22 characters; super secret Aether JWT signing key @@ -108,6 +111,11 @@ AE_APP_DIR=/srv/aether_app AE_APP_LOG_PATH="/logs/aether_app.log" AE_APP_WORKERS=2 AE_APP_THREADS=1 +AE_APP_GUNICORN_TIMEOUT=1200 # (default=30; should be higher) +AE_APP_GUNICORN_GRACEFUL_TIMEOUT=20 # (default=30) +AE_APP_GUNICORN_KEEPALIVE=30 # (default=2) +AE_APP_GUNICORN_WORKERS=2 # (default=2) +AE_APP_GUNICORN_THREADS=1 # (default=1) AE_APP_RELOAD=True # Generate a new key with: # python -c 'import os; print(os.urandom(16))' AE_APP_CACHE_SECRET_KEY="$\x93\x12\xb4R\x80R\xb5\xe50\xa0k\xc8#RN" diff --git a/conf/aether_fastapi_gunicorn_conf.py b/conf/aether_fastapi_gunicorn_conf.py index 4e22c85..d57579c 100644 --- a/conf/aether_fastapi_gunicorn_conf.py +++ b/conf/aether_fastapi_gunicorn_conf.py @@ -22,9 +22,9 @@ wsgi_app = "app.main:app" # default_proc_name = "app.main:app" # Setting a long timeout since some FastAPI API requests may take a while -timeout = 2100 # default 30; 1200 is NOT enough; worker process silent then kill and restart -graceful_timeout = 20 # default 30; timeout after restart signal; tried 10 2023-07-11 -keepalive = 30 # default 2; setting higher because behind load balancer (nginx); tried 10 2023-07-11 +timeout = os.getenv('AE_API_GUNICORN_TIMEOUT', 2100) # default 30; 1200 is NOT enough; worker process silent then kill and restart +graceful_timeout = os.getenv('AE_API_GUNICORN_GRACEFUL_TIMEOUT', 20) # default 30; timeout after restart signal; tried 10 2023-07-11 +keepalive = os.getenv('AE_API_GUNICORN_KEEPALIVE', 30) # default 2; setting higher because behind load balancer (nginx); tried 10 2023-07-11 # Reload does not work correctly with UvicornWorker # https://github.com/benoitc/gunicorn/issues/2339 @@ -37,7 +37,7 @@ worker_class = "uvicorn.workers.UvicornWorker" # default "sync" # Works are processes, not threads # workers = 9 # default 1; use 10ish for production; 2 to 4 times the number of cores # threads = 1 # default 1; only affects Gthread worker type -workers = os.getenv('AE_API_WORKERS', 2) -threads = os.getenv('AE_API_THREADS', 2) +workers = os.getenv('AE_API_GUNICORN_WORKERS', 2) +threads = os.getenv('AE_API_GUNICORN_THREADS', 2) # umask = '007' diff --git a/conf/aether_flask_gunicorn_conf.py b/conf/aether_flask_gunicorn_conf.py index 31ba4ba..bb8049b 100644 --- a/conf/aether_flask_gunicorn_conf.py +++ b/conf/aether_flask_gunicorn_conf.py @@ -22,9 +22,9 @@ wsgi_app = "run_server:app" # default_proc_name = "run_server:app" # Setting a longer timeout since some Flask app requests may take a while -timeout = 1200 # default 30; worker process silent then kill and restart -graceful_timeout = 20 -keepalive = 300 # default 2; setting higher because behind load balancer (nginx) +timeout = os.getenv('AE_APP_GUNICORN_TIMEOUT', 1200) # default 30; worker process silent then kill and restart +graceful_timeout = os.getenv('AE_APP_GUNICORN_GRACEFUL_TIMEOUT', 20) +keepalive = os.getenv('AE_APP_GUNICORN_KEEPALIVE', 300) # default 2; setting higher because behind load balancer (nginx) # Disable reload if using more than one thread reload = True @@ -33,8 +33,8 @@ reload = True # Works are processes, not threads # workers = 9 # default 1; use 10ish for production; 2 to 4 times the number of cores # threads = 1 # default 1; only affects Gthread worker type -workers = os.getenv('AE_APP_WORKERS', 2) -threads = os.getenv('AE_APP_THREADS', 2) +workers = os.getenv('AE_APP_GUNICORN_WORKERS', 2) +threads = os.getenv('AE_APP_GUNICORN_THREADS', 2) # umask = '007'