[LA.pm] Problem with FastCGI under Apache 2

Benjamin J. Tilly ben_tilly at operamail.com
Fri Feb 10 13:41:05 PST 2006


"Geoffrey Young" <geoff at modperlcookbook.org> wrote:
> > With unsafe signals, if something makes existing database handles become
> > invalid, we lose our currently executing pages and have the possibility
> > of unhappy behaviour until the Apache child dies.  With safe signals we
> > have a guaranteed site outage as requests pile up for mod_perl processes
> > which are trying to figure out whether they have a database handle.
> 
> hopefully, you know that at least with mp1 you don't need to wait around for
> the child to die for an unspecified amount of time by using
> child_terminate(), which offers a graceful child exit.  mp2 offers similar
> functionality but is far less graceful.

It is good to know that, but I'm not entirely sure how I'm supposed to use this knowledge.  Here is the exact scenario.

We're using mod_perl (in one place mp1, another mp2) with a handler that grabs a dbh and puts it in a global variable for general use.  It grabs the dbh with connect_cached.  Which means that if it is the first request in this Apache child, we connect to the database, otherwise we're probably just going to use our existing connection.

The problem is that if something unexpectedly invalidates the connections (eg unexpected database restart) then connect_cached can take a painfully long time to figure out that the connection is bad and it needs to try reconnecting.  Using unsafe signals we can guarantee that it will figure that out in a much more reasonable timeframe (eg 15 seconds).

This should be a *very* rare circumstance.  I've seen it happen in production once or twice in the last 3 years.  (And well believe that better processes could make it even rarer.)  But it happens to me in development quite frequently.  (My development server is my desktop, there is a firewall between me and the development database, and that firewall drops TCP/IP connections after 2 hours.  So if I am working on something else, then my site has lost its database connections.  It is nice for your site to recover on its own without manual intervention ASAP.

> if you're using Apache::DBI this leveraging something like this
> 
>    http://www.modperlcookbook.org/code/ch04/Cookbook/DBIUtils.pm
> 
> might be of some help as well.

I forget why we don't use Apache::DBI, but we don't because it caused problems for us.

Anyways terminating when we decide to terminate isn't a problem.  The problem is deciding whether we need to terminate the database connection.  (We probably don't.)

Cheers,
Ben


More information about the Losangeles-pm mailing list