Problems with Cached DBI connections

Tom Insam tom at jerakeen.org
Tue Nov 14 12:33:29 GMT 2006


On Nov 13, 2006, at 22:09, Dave Hodgkinson wrote:

>
> On 13 Nov 2006, at 19:30, Simon Wistow wrote:
>
>>
>> Has anybody else seen a phenomenom where they're using cached DBI
>> connections but N processes run out of connections despite the  
>> fact that
>> the DB (in this case MySQL - not sure if that's relevant) has a
>> connection limit of M where N<M?
>
>
> Are you using a variety of credentials to connect? If so, each
> username/database combo uses a connection.

I was once bitten by a custom error handler subroutine on my connect  
call - something like

my $dbh = DBI->connect_cached( ...
   HandleError => sub {
     my $error = shift;
     ....
   });

Because _all_ the params to connect_cached are used to decide that  
this should be a distinct connection, and the sub {} is an anonymous  
that gets redefined every time you call the connect call, this lead  
quickly to every apache process making 2000 database connections, and  
never letting any of them go.

oops.

tom



More information about the london.pm mailing list