Django with MySQL: problem solved?

Post Info

Author

Eugene Lazutkin

Date

Posted: Monday, September 5, 2005

Categories

Development::DB::MySQL (4)
Development::Python::Django (45)

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:  del.icio.us  Digg  Reddit  StumbleUpon  Facebook    Subscribe to this blog:  Bloglines  Netvibes

Most recent related documents:

Documents published at about the same time:

Made with Django.