Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ping MySQL to keep connection alive in Django

I have a bunch of workers waiting for tasks (using Django as ORM). My problem is that if there's no task for a given amount of time (whatever MySQL wait_timeout variable is set to) the MySQL connection times out and hence the worker dies.

My first approach to solve this problem was simply to increase the wait_timeout to a higher integer, but I thought a better solution might be to ping MySQL like every 30mins or so if there has been no task to keep the connection alive.

So my question is; how can I using the Django ORM simply ping MySQL to keep the connection alive? What's the best practice here, just do a simple stupid query ?

like image 815
Niklas9 Avatar asked Nov 01 '13 10:11

Niklas9


1 Answers

Setup a connection pool or manually connect the worker as suggested by @ProblemFactory

http://dev.mysql.com/doc/refman/5.6/en/connector-python-connection-pooling.html

like image 143
Hedde van der Heide Avatar answered Oct 17 '22 22:10

Hedde van der Heide