Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Your results will depend – will depend entirely – on “exactly what-it-is that the threads or processes are doing.”

In this case, you seem to be calculating factorials.   This is a so-called CPU-Bound activity, in which every thread will always consume its full time-slice, until it is pre-empted by another thread which will dutifully consume its full time-slice, and so on.   Two threads will run twice as fast ass one; four threads, twice again as fast as two; but there, the improvements will stop, and slightly degrade to account for the overhead spent round-robin switching between threads.   (Probably too small to see.)   The capacity of the only ruling-constraint – the CPU – has been reached, and fully utilized, and of course cannot be exceeded.

Most real-world activities are I/O-Bound, either directly, due to actual input/output that they do, or indirectly, due to virtual-memory page faults which they induce by trying to use (way ...)too-much memory.   These activities are dependent in their execution speed on the capacity of the system to perform I/O.   The threads/processes spend nearly all of their time waiting for an I/O activity:   either voluntarily, for an operation that they requested, or involuntarily due to a page-fault.   CPU utilization is relatively trivial.

Trouble is, when an I/O-bound activity begins to get stoppered-up, the degredation of throughput is “at first, linear, then exponential.”   A plot of the performance curve has a nearly right-angle “elbow” to it ... a point called thrashing, or “hitting the wall” (with a grisly and final “thud”).   (Example:   “6-at-a-time = 4 minutes; 12-at-a-time = 9 hours.”   A bit extreme, yes, but long ago I saw it happen.)

To avoid this, the best approach is to do what’s done in any fast-food restaurant:   maintain a manageable number of workers, each of which processes work from a thread-safe queue, so that, no matter how much work there is to do, the work in-process can be limited and adjusted.   (The waiting-line just gets longer, but the transactions/second remains stable.)   There are plenty of workload-management packages in CPAN to do this.


In reply to Re: Useful number of childs revisited by sundialsvc4
in thread Useful number of childs revisited [SOLVED] by karlgoethebier

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 15:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found