debiandude has asked for the wisdom of the Perl Monks concerning the following question:

I have currently converted my code to use CDBI instead of inline SQL statements. However, I was browsing my test site yesterday and got a weird error. I went and checked the Apache logs and it turned out that there were too many concurent connections to my database.

This of course couldn't be true since I was the only one viewing it. However, I was confused becuase that means that CDBI isn't closing its connection. I was unaware (from my reading of the docs) of a need to do the equilalant of a:

$sth->finish and $dbh->disconnect

with CDBI.

In reality this probably is a result of me using mod_perl. But I still can't figure out how to fix this. I checked the CDBI wiki which had a page on problems using CDBI with mod_perl but I didn't see what I am experiencing discussed.

Anyone have any clues?

Update:

I am not using Apache::DBI. I will look into it. Right now there are no calls to finish. I think 200 database connections is plenty. Raising it would just artically hid the problem. For example, if I just hit refresh on my main pain and type this into my mysql termianl:

show status;
The value of Threads_connected seems to increase unbounded (every time I refresh it increments by 1). This should not happen. It should increase to a certain number and then stop.

Replies are listed 'Best First'.
Re: Class::DBI and mod_perl
by merlyn (Sage) on Jun 16, 2006 at 03:13 UTC
Re: Class::DBI and mod_perl
by submersible_toaster (Chaplain) on Jun 16, 2006 at 03:15 UTC

    Remember there is no sharing of those database connections between apache processes, so to start with you will have as many db connections as apache daemons. Are you using Apache::DBI ?


    I can't believe it's not psellchecked
Re: Class::DBI and mod_perl
by perrin (Chancellor) on Jun 16, 2006 at 03:46 UTC
    The way to fix this is to increase the number of connections your database allows. You shouldn't be closing your connections. It's much faster to use persistent ones.