Re: Class::DBI and fork



"golden" <iang@xxxxxxxxxxxxx> 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::DBI, 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
.



Relevant Pages

  • Re: FreeBSD deadlock (with fork?)
    ... multiple threads. ... Do you create threads, which then fork(), or do you forkand then create ... I could limit the forking to a single thread ... One option I considered was forking a 'slave' program that then does all the ...
    (freebsd-current)
  • Re: FreeBSD deadlock (with fork?)
    ... The problem is the program often deadlocks, ... Do you create threads, which then fork(), or do you forkand then create ... I could limit the forking to a single thread ... One option I considered was forking a 'slave' program that then does all the ...
    (freebsd-current)
  • Re: [9fans] APE and listen(2B)
    ... not forking would make more sense. ... you could dispense with the ... forand the fork. ... the code suggests that the purpose of the separate proc is to ...
    (comp.os.plan9)
  • Re: Transport Agent
    ... Now I see how forking a message is working. ... Take a look at the following blog for information on how to fork for ... individual recipients. ... > seems to fork the message somehow. ...
    (microsoft.public.exchange.development)
  • Re: Preventing Accidentally Fork Bombing My Box
    ... I have a bad habit of accidentally fork ... > This is a pretty good sign that you are over-using the fork command. ... Many real-world forking examples involve calling ... forkin a loop. ...
    (perl.beginners)