From f53434f93517abe7bcc4249ce33a92a2e78c46d7 Mon Sep 17 00:00:00 2001 From: Igor Shishkin Date: Fri, 28 Aug 2015 14:45:40 +0300 Subject: [PATCH] Tuning pool_recycle to avoid MySQL server gone away Some time after lodgeit application have no load SQLalchemy connection expires and application dies with 5xx error and MySQL Server gone away exception. By using a shorter default pool_recycle of 3600s which can also be tweaked using environment variables, it allows you to avoid dealing with this issue. Change-Id: I79eb823458c604b2faff9bb1e9531c45fc1ed3cb --- lodgeit/application.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lodgeit/application.py b/lodgeit/application.py index fcc3129..4c1686a 100644 --- a/lodgeit/application.py +++ b/lodgeit/application.py @@ -24,11 +24,12 @@ from lodgeit.controllers import get_controller class LodgeIt(object): """The WSGI Application""" - def __init__(self, dburi, secret_key): + def __init__(self, dburi, secret_key, pool_recycle=3600): self.secret_key = secret_key #: bind metadata, create engine and create all tables - self.engine = engine = create_engine(dburi, convert_unicode=True) + self.engine = engine = create_engine( + dburi, convert_unicode=True, pool_recycle=pool_recycle) db.metadata.bind = engine db.metadata.create_all(engine, [Paste.__table__]) @@ -84,7 +85,8 @@ def make_app(dburi=None, secret_key=None, debug=False, shell=False): secret_key = os.getenv('LODGEIT_SECRET_KEY') static_path = os.path.join(os.path.dirname(__file__), 'static') - app = LodgeIt(dburi, secret_key) + app = LodgeIt(dburi, secret_key, + pool_recycle=os.getenv('LODGEIT_POOL_RECYCLE', 3600)) if debug: app.engine.echo = True app.bind_to_context()