[mod_python] MySQL Session implementation?

Mike Looijmans nlv11281 at natlab.research.philips.com
Mon Jul 3 06:53:47 EDT 2006


> One important thing not to overlook if you are going to implement a
> MySQLSession class is database connection pooling.

In the particalur case of MySQL, the need may not be that high.

I did some benchmarking around 2002 with the MySQL versions of that time 
(somewhere around 4.0), and could not prove the pooled version to be any 
faster than the non-pooled. Most of the time was spent in other parts of 
the request handling, setting up the database connection to MySQL 
appeared to be neglegible.

Note that this behaviour is specific to MySQL using a UNIX socket on the 
local host. Oracle for example often took a few seconds to set up a 
connection. On a TCP socket, the delay is a bit more. You might consider 
using MySQL replication to allow the DB to run on all the web servers 
locally while still sharing all data between them.

Having said all that, a thread safe DB pool takes only about ten lines 
of Python code to create, so it's a piece of cake.

When you ARE pooling connections, be aware of the following:

- The database will not like thousands of open (but idle) connections. 
Close them if you have too many spare ones.

- Connections may stay open for days. Be sure to do some kind of "ping" 
on a connection when you retrieve it from the pool, or be prepared to 
handle connection-lost errors later on.



More information about the Mod_python mailing list