[Zope] Database connections

Paul Everitt Paul@digicool.com
Tue, 23 Mar 1999 10:48:49 -0500


Oleg writes:
>    I've finished large project using pure CGI concept (I used Neale's
> html.py). Now I (and my boss) are thinking of switching to Zope, or at
> least ZTemplates.
> 
>    While playing with Zope and SQL (I am using Postgres, hence ZPygres
> Database Adapter), I found that Zope, when loaded into memory 
> by Zope.cgi
> (I am using Apache, and need to use in the future) opens a database
> connection for every Folder where I created Connection object.

Ahh, no need.  Just put one Database Connection object in the top folder
and all the subfolders will "acquire" it.  That is, any SQL Method
defined lower down can use it.

>    It is bad, as I have many databases, so Zope eats up 
> memory. Another
> problem - what would do Zope if I restart Postgres (so all current
> connections break)? Would Zope reestablish connections or just report
> error?

It should re-establish the connection.  If it doesn't then there's a
bug.  This works fine with all the Database Adapters I've used.

>    How could I limit number of connections Zope opens? How could I

There is one connection per Database Connection object.

> define a timeout, after which Zope close a connection if there is no

Hmm, this is quite a hard thing to do, unfortunately.

> activity between Zope and Postgres? and reestablish connection when
> application ask for SQL data?
> 
>    With ZTemplates and CGI all these questions has one easy 
> (but not so
> nice) answer - there is no constant connection, a connection 
> established on
> every CGI invocation.

Of course this means the CPU gets a tremendous beating on every request
and the response time goes down.
 
> PS. BTW, I wrote short introduction to Zope in Russian:
> http://sun.med.ru/~phd/Russian/Zope/
>    Any Russian here to verify my understanding of Zope?

Mind if I add a blurb to the Zope News about it?

--Paul