Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Given an running init process and a parent process which is forked, you're limited to 2**15 - 2 = 32766 forked processes, depending on your system, also 2**16 - 2 = 65533 may be possible :-)

Okay, let's stop kidding.
There is no system- or Perl limit of forked processes, but each fork and each process need CPU time and memory.

Keep your parent as slim as possible before forking id you need many childs. This means: Load only modules used by all childs, don't put big things into variables, etc. Also keep an eye on child/zombie cleanup. Use a wait-loop from time to time to catch childs where you missed the CHLD signal.

I wrote a big forker deamon some time ago. It processes a Job queue where most jobs result in HTTP requests to external targets. The parent ran the queue, did some locking-checks on the queue items and then forked and used the child to load the item and process it. It was limited to a fixed amount of child processes and childs per HTTP target to stay within the servers resource limits but it was able to process more than 20.000 jobs per hour.
(There are other ways to do this, I know, but in this situation safty was more critical than good design and as too many people worked on the different job processors, this was the safest way to keep the daemon running no matter what a child did or not.)

In reply to Re: Number of forks by Sewi
in thread Number of forks by nagalenoj

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [marto]: Corion, I'll talk to you later, but that are is generally fine :)
    [hippo]: Just not sure that the expense and hassle is worth the benefit.
    [LanX]: expense? .... meeting ppl is inspiring ...
    [LanX]: ... and it might be your last chance ... I heard Perl is dead! OO

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (11)
    As of 2018-06-20 09:37 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (116 votes). Check out past polls.