seaver has asked for the wisdom of the Perl Monks concerning the following question:
Starting a new thread from this one .
Wehn I originally wrote my code, I opened a DBD::mysql connection at the start of the script, and closed it at the end of the script. This worked just fine.
But then someday I updated perl, and I think my OS (from RH7.3 to RH9) and the DBD::mysql connection would consistently close prematurely.
I read in a user-group something along the lines of the instability of the connection, and how you need to reduce the 'time' between open and close
So I re-wrote my program so that it opened and closed every time it wanted to do something, and it works just fine.
But now, after having profiled my script, it's obvious that it takes up most of the time in my script!! (%10)
So my first step in optimisation is to reduce the number of times a new DBD::mysql connection is opened and closed, but I can't remember what the original problem was, and if the connection is unstable after one request, is it possible to do anything about this?
Here's an example of one function in my DB module:
Every function just simply opens and closes WITHIN the function. My original code just opened a handle for the whole module, accessible from every function, but this was unstablesub getNullEndIds{ my $self = shift; my $dbh = DBI->connect($dbi,"monster_mirror","m1rr0r",{'RaiseError +' => 1}); my $sth = $dbh->prepare("SELECT id from high where end IS NULL"); $sth->execute(); my @id; while(my @dummy = $sth->fetchrow_array()){ push(@id,$dummy[0]); } $sth->finish(); $dbh->disconnect(); return @id; }
Cheers
Sam
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBD::mysql connections
by Joost (Canon) on Jun 17, 2004 at 15:18 UTC | |
by seaver (Pilgrim) on Jun 17, 2004 at 15:25 UTC | |
by shemp (Deacon) on Jun 17, 2004 at 16:30 UTC | |
by seaver (Pilgrim) on Jun 17, 2004 at 18:11 UTC | |
|
Re: DBD::mysql connections
by hmerrill (Friar) on Jun 17, 2004 at 18:20 UTC | |
|
Re: DBD::mysql connections
by Anonymous Monk on Jun 17, 2004 at 14:58 UTC | |
by edan (Curate) on Jun 17, 2004 at 15:05 UTC | |
by seaver (Pilgrim) on Jun 17, 2004 at 15:09 UTC | |
by Anonymous Monk on Jun 18, 2004 at 02:25 UTC |