Aug 27 - Add MySQL optimize and security check
This commit is contained in:
@@ -32,6 +32,34 @@ class Config:
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
SQLALCHEMY_ECHO = False
|
||||
|
||||
# ── Connection pool ─────────────────────────────────────────────────────
|
||||
# Without these the pool runs on library defaults, which is where the
|
||||
# intermittent OperationalError 2006 ("MySQL server has gone away") comes
|
||||
# from: MySQL closes a connection after wait_timeout (8h by default) and
|
||||
# SQLAlchemy hands the dead socket to the next request.
|
||||
#
|
||||
# pool_pre_ping — cheap liveness check before a connection is handed out;
|
||||
# a dead one is discarded and replaced transparently.
|
||||
# pool_recycle — retire connections after 30 min, well under any sane
|
||||
# wait_timeout, so they are never the stale ones.
|
||||
# pool_size / — Gunicorn runs sync workers (cpu*2+1), and each worker
|
||||
# max_overflow holds its OWN pool. Library defaults (5 + 10) mean a
|
||||
# 9-worker box can open 135 connections against a
|
||||
# max_connections of 151. A sync worker serves one
|
||||
# request at a time, so it needs one connection in
|
||||
# steady state; the small overflow is headroom for
|
||||
# background email/notification threads.
|
||||
#
|
||||
# Tune with scripts/db_health.py, which cross-checks these against the
|
||||
# server's live max_connections and wait_timeout.
|
||||
SQLALCHEMY_ENGINE_OPTIONS = {
|
||||
'pool_pre_ping': True,
|
||||
'pool_recycle': int(os.environ.get('DB_POOL_RECYCLE', '1800')),
|
||||
'pool_size': int(os.environ.get('DB_POOL_SIZE', '5')),
|
||||
'max_overflow': int(os.environ.get('DB_MAX_OVERFLOW', '5')),
|
||||
'pool_timeout': 30,
|
||||
}
|
||||
|
||||
# ── File uploads ────────────────────────────────────────────────────────
|
||||
UPLOAD_FOLDER = os.path.join(basedir, 'app/static/uploads')
|
||||
MAX_CONTENT_LENGTH = 50 * 1024 * 1024 # 50 MB
|
||||
|
||||
Reference in New Issue
Block a user