Django with MySQL: problem solved?
It looks like the problem is solved. Django creates one (1) connection to database and reuses it to handle requests. Multithreaded FastCGI creates threads to handle requests. These threads make requests to MySQL, which gets confused and loses its cool^H^Honnection. This process is random and compounded with multiple web requests at the same time. For example, if Google Web Accelerator decided to prefetch some pages, your web site would be hosed.
Luckily, the only place, which needs fixing, is one small class: mysql.DatabaseWrapper.
I added a dictionary of connections so every thread will have it's own connection. Apparently it solved the problem. Additionally I ping connection to make sure it is not timed-out, and do some simple clean up, when threads are finished.
PostgreSQL doesn't have this problem. For those of you keeping score at home, MySQL loses a cookie point.
Save/recommend this post:
Subscribe to this blog:
Most recent related documents:
Documents published at about the same time:
- Something wrong with simple cache — September 9, 2005
- Say no more! Say no more! — September 8, 2005
- Django on Dreamhost: happy end — September 7, 2005
- Opera and Dojo — September 5, 2005
- More on MySQL and Django problems — September 5, 2005
- Django and MySQLdb worries — September 4, 2005
- Dojo: 1st impression — September 3, 2005
- New Design 0.1 is here! — September 2, 2005

