About a month ago we discussed about the shortcomings of the database
connection pooling module MiscUtils/DBPool.py. For instance, lost
connections will never be recovered. Meanwhile, I have implemented the
discussed issues in a suite of tools I called DBUtils (see
http://svn.w4py.org/home/chrisz/DBUtils/), containing the following modules:
SimplePooledDB.py: Virtually the same as DBPool.py (cosmetical improvements)
SolidDB.py: solid database connections (transparently opens lost
PersistentDB.py: thread-affine persistent connections (based on SolidDB)
PooledDB.py: pooled connections (based on SolidDB)
PooledDB is a lot more sophisticated than SimplePooledDB (DBPool), but I
think it is good to keep the simple version as well for reference.
Through the use of SolidDB, you can even restart the database, and the
Webware application will still work nicely afterwards.
PersistentDB simply connects every AppServer thread 1:1 with a database
connection. This avoids a lot of trouble and consideration of threading
issues. If will work best if the AppServer threads stay stable, i.e.
MinServerThreads = MaxServerThreads, and if the application has a lot of
If this is not the case and you don’t want the 1:1 coupling and
configure the servlet and database resources independently, you should
use PooledDB instead. This module is pretty complex because of the
multi-threading issues, but it should be thread-safe and work nicely. It
even allows you to choose between sharable connections for simple
queries and unsharable connections which should be used if transactions
The suite also contains special versions of these 4 modules for the
classic PyGreSQL API.
If possible, give me some feedback. If nobody is against, I would like
to remove DBPool.py from MiscUtils and to add the whole DBUtils suite as
a new Webware plugin instead.
Warren, it would be also great if you could add your “DbConnectionPool”
to the DBUtils suite, as another DB pooling module. DBConnectionPool
uses a different approach for dealing with bad connections (by running
an “expiration” thread), so it would be good to have it as an alternative.