Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Class::DBI and fork

Reply
Thread Tools

Class::DBI and fork

 
 
golden
Guest
Posts: n/a
 
      08-31-2005
Hi,

I have been using class DBI for generating reports and till now most of
the work has been done off-hours so performance was not quite an issue.


I would now like to have some reports run interactively by a user, but
some of the has_many relationships take a significant amount of time.

So, for my inventory system, I was thinking about taking a list of
products from a user and forking parallell processes for each product
to get all relationships. Each fork would write to a separate file,
then I can reap all the files after completing all products.

The forking was done with Parallel::ForkManager, but when I run the
code, I get all sorts of Errors from Class:BI, but I do not get those
errors if I remove forking. I suspect that the dbh file handle gets
trashed during the fork.

Can anybody comment or suggest an alternative?

Thanks,

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      08-31-2005
"golden" <(E-Mail Removed)> wrote:

.....
> I would now like to have some reports run interactively by a user, but
> some of the has_many relationships take a significant amount of time.

....
> The forking was done with Parallel::ForkManager, but when I run the
> code, I get all sorts of Errors from Class:BI, but I do not get those
> errors if I remove forking. I suspect that the dbh file handle gets
> trashed during the fork.
>
> Can anybody comment or suggest an alternative?


The best alternative may be to fix your database. If your database can't
efficiently handle one query at a time, slamming it with multiple queries
at a time is just as likely to make things worse as make them better. YMMV

Each child almost certainly needs it's own connection. So make your
database connections after the fork, rather than before. If you need a
database connection before you do the fork, then close that connection
before the fork, and then reconnect after.

If you need a database connection which survives the fork in only one of
the forked processes, (i.e. because a single transaction spans the fork),
then set InactiveDestroy in every process other than the one that still
needs the handle. (And in general, I believe that the one that keeps the
handle active must be the original process, not one of the spawned ones).


Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
os.fork and pty.fork Eric Snow Python 0 01-08-2009 06:32 AM
spawn* or exec* and fork, what should I use and how ? Lingyun Yang Python 4 12-16-2004 08:35 AM
objects and fork command? Doug Nichols Perl 1 08-08-2004 11:07 AM
pipe(), fork(), exec(), ... providing input to and capturing output of a child process Hoegje C++ 2 12-05-2003 04:03 PM
tcp and fork marconi C Programming 4 09-10-2003 03:01 AM



Advertisments