[mod_python] Persist database conn, or pers. variables - where I put them ?

Mike Looijmans nlv11281 at natlab.research.philips.com
Thu Sep 28 05:45:42 EDT 2006

> Example: FireBird connect is very slow. When I not reuse the connection, 
> I get the page in 5-10 seconds. When I reuse, the generating is below 1 
> second.

For this kind of problem, connection pooling is a good solution indeed. If you have control over the 
Apache server, force it to use a "mostly" threading worker mpm (on most unix systems, it defaults to 
prefork). This allows you to share the Python interpreter for many requests, and thus the 
namespaces. Then you can create a simple connection pool as a module where you grab and put back 
connection objects when you're done with it.

Cleanup is not a problem. If the apache child process dies, the connections will be closed by the OS 
and Firebird will cleanup the associated resources.

If you must use multi-processing apache, either use a proxy (can be HTTP or SQL proxy as suggested 
already) in a separate process, or make sure that firebird can handle things like 200 open idle 
connections efficiently.


More information about the Mod_python mailing list