On Fri, 23 Jun 2006, Tobias Kremer wrote:
> Enter mod_perl. I'd like to initialize the object only ONCE during
> server startup because there is some heavy startup processing going on
> with data from the database which I don't want to be done on every
> request. The final state (think data structures) should then be saved
> within the object's attributes for later quick and easy retrieval during
> the request phase. Now I hope you can see the problem: The handle
> created during server startup will not be cached by Apache::DBI,
> subsequent database queries to the database by the module will IMHO use
> this non-cached connection which is _shared_ among all apache child
> processes. AFAIK that's what could get me into serious trouble.

That doesn't happen.  The Perl interpreter and all objects in it 
get cloned to each Apache child.  Whatever you set up in startup 
is cloned for each child, so it isn't actually the same 
structure, package or symbol table.  You can pre-populate data 
to be cloned to children, but children don't share any memory. 

That means that every child process is going to make its own 
connection.  FYI this can result in a large number of 
connections and you need to tune your database connection 
timeout so that it times out within a few seconds.  If the 
server is busy, and every child reconnects each time through 
Apache::DBI, this will be fine, because Apache::DBI will re-use 
the handles that are still connected.  But if it is not busy, 
you don't wind up with 10,000 idle handles that drive your DB 
out of memory and prevent new connections.

You ought to check out DBIx::Class.  Not only would it roll the 
wheels you are trying to re-invent with your objects (I tried 
that too), but under FastCGI it actually does what you want -- 
all processes use the same connection, and it manages them.

Under that kind of environment, it sounds like you need to start 
programming with SQL transactions to keep your data straight.

Mark

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to