Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: threads: spawn early to avoid the crush.

by vagnerr (Prior)
on Mar 02, 2006 at 13:32 UTC ( #533876=note: print w/ replies, xml ) Need Help??


in reply to threads: spawn early to avoid the crush.

We had a similar issue in the past with a perl daemon that forked multiple working children to handle various tasks. Obviously the larger you forking process is the larger the children. His solution was to have the daemon imediatly fork off the "main" process and keep the small initial parent just for the job of forking new processes. If the main program needed another process it would ask the original parent to do it for it. As all the parent was doing was forking new processes it remained nice and small.
He also got to call it a realy cool name. "The Motherforker!" :-)



_____________________
Remember that amateurs built Noah's Ark. Professionals built the Titanic.


Comment on Re: threads: spawn early to avoid the crush.
Re^2: threads: spawn early to avoid the crush.
by BrowserUk (Pope) on Mar 02, 2006 at 14:08 UTC
    If the main program needed another process it would ask the original parent to do it for it.

    Could you explain that in a bit more detail for me? I've never done much with fork, especially in Perl.

    • How does the main code inform it's parent when it is time to create another process?
    • If there can be multiple other processes that might need to be run, how does the main code tell teh parent which one to create?
    • How does the new process get it's parameters?
    • How does the main code retrieve the results from the new process?

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Here's a simple answer to interprocess communication: use pipes.
      #!/usr/bin/perl -w #use forking open to start 3 more processes unless (open X, "-|") { print 1+5; exit }; # X=1+5 unless (open Y, "-|") { print 2*3; exit }; # Y=2*3 unless (open Z, "-|") { print <X>+<Y>; exit }; # Z=X+Y print "Z = "; print <Z>."\n";
Re^2: threads: spawn early to avoid the crush.
by perrin (Chancellor) on Mar 02, 2006 at 18:13 UTC
    If your daemon was forking, what you did was probably not a good idea. Although the processes appear to be larger when forking from a larger process, most of that memory is shared by copy-on-write. This is not the case with Perl threads, which is why BrowserUK's advice is correct for them.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://533876]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2014-11-22 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (123 votes), past polls