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
This commit is contained in:
parent
54727daa85
commit
f53434f935
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user