From 7679a62cf1c0039cf7207bca8fcab4727fd15242 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Wed, 12 Jul 2023 15:39:45 -0400 Subject: [PATCH] General improvements. --- .env.default | 14 ++++++++++++-- conf/aether_api_config.py | 4 ++++ conf/aether_fastapi_gunicorn_conf.py | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.env.default b/.env.default index 23cffb6..48e43d8 100644 --- a/.env.default +++ b/.env.default @@ -61,6 +61,13 @@ AE_DB_NAME=aether_dev AE_DB_USERNAME=osit_aether AE_DB_PASSWORD="the password with $$ escape" +# wait_timeout (MariaDB) is how long to keep an idle DB connection +AE_DB_WAIT_TIMEOUT=1800 # Not yet used! +# connection_timeout (MariaDB) is how long to try and create a new DB connection; bad handshake +AE_DB_CONNECTION_TIMEOUT=15 +# pool_recycle (SQLAlchemy) is how long to keep using a particular connection that has passed a certain age +AE_DB_POOL_RECYCLE=1800 + AE_DB_V5_SERVER=linode.oneskyit.com AE_DB_V5_PORT=3306 AE_DB_V5_NAME=aether_v5_dev @@ -78,12 +85,15 @@ AE_SMTP_USERNAME=send_mail # AE_SMTP_PASSWORD="not currently used" +# Gunicorn workers and threads: +# https://docs.gunicorn.org/en/stable/design.html#how-many-workers + # Aether API specific config options (FastAPI) # AE_API_CFG_ID=0 # NOT CURRENTLY NEED OR USED AE_API_ENV=development AE_API_DIR=/srv/aether_api AE_API_LOG_PATH="/logs/aether_api.log" -AE_API_WORKERS=1 +AE_API_WORKERS=2 AE_API_THREADS=1 AE_API_RELOAD=False @@ -96,7 +106,7 @@ AE_APP_UX_MODE=default # AE_APP_UX_MODE=native AE_APP_DIR=/srv/aether_app AE_APP_LOG_PATH="/logs/aether_app.log" -AE_APP_WORKERS=1 +AE_APP_WORKERS=2 AE_APP_THREADS=1 AE_APP_RELOAD=True # Generate a new key with: # python -c 'import os; print(os.urandom(16))' diff --git a/conf/aether_api_config.py b/conf/aether_api_config.py index 05ef13c..b83525e 100644 --- a/conf/aether_api_config.py +++ b/conf/aether_api_config.py @@ -26,6 +26,10 @@ class Settings(BaseSettings): DB['username'] = os.getenv('AE_DB_USERNAME', None) # 'osit_aether' # 'onesky_aether' DB['password'] = os.getenv('AE_DB_PASSWORD', None) # SQLALCHEMY_DB_URI = 'mysql://'+DB['username']+':'+DB['password']+'@'+DB['server']+'/'+DB['name'] + + DB['wait_timeout'] = int(os.getenv('AE_DB_WAIT_TIMEOUT', 1800)) # default = 28800; Time (seconds) that the server waits for a connection to become active before closing it. + DB['connect_timeout'] = int(os.getenv('AE_DB_CONNECTION_TIMEOUT', 20)) # default = 10; Time (seconds) that the server waits for a connection to become active before closing it. + DB['pool_recycle'] = int(os.getenv('AE_DB_POOL_RECYCLE', 1800)) # default = ?; Related to SQLAlchemy # Aether API log files paths diff --git a/conf/aether_fastapi_gunicorn_conf.py b/conf/aether_fastapi_gunicorn_conf.py index 655c93c..94d543b 100644 --- a/conf/aether_fastapi_gunicorn_conf.py +++ b/conf/aether_fastapi_gunicorn_conf.py @@ -24,7 +24,7 @@ wsgi_app = "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 = 10 # default 30; timeout after restart signal -keepalive = 2 # default 2; setting higher because behind load balancer (nginx) +keepalive = 30 # default 2; setting higher because behind load balancer (nginx) # Reload does not work correctly with UvicornWorker # https://github.com/benoitc/gunicorn/issues/2339