Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

First of all, and most importantly, I would challenge your notion of using “thousands of threads.”   It won’t help, and it will hurt, because the processing that you describe is I/O-bound.   Don’t make that disk-drive move its read/write head around any more than you have to, because that is what costs you milliseconds apiece.   Most of the time, in situations that have been multithreaded but are not good candidates for it, all-but-one of your threads will be waiting for that disk-drive.   Remember that multithreading divides the CPU resource, and does not multiply anything.

Secondly ... consider using the xargs command with the -p numprocs option to conveniently spawn numprocs instances of a simple single-threaded program which takes a filename as its command-line parameter and processes just that one file, then dies.   No funky programming required, and you can easily tweak the number of processes.   (You will find the “sweet spot” to be quite small, and it just might be “1.”)   Build a file containing a list of all the filenames to be processed.   (The ls command can do that.)

For multithreaded processing in-general, each thread or process should be the true master of its own affairs, capable of trapping runtime errors and of using a timer-signal to interrupt what it is doing without losing control of the situation.   (Ditto if it is just a single-thread.)   Generally it is not a good idea to put a pistol to the head of any process because you do not know exactly what it was doing when its head exploded.   The process or thread should survive, no matter what, and exit graciously and cleanly.   The parent’s one and only responsibility is to mind the children (aye, ’twas ever thus ...), who do all the work as well as all the communication with the outside world.

Finally, search CPAN to find the many existing frameworks that are already out there to do this very common thing.   (xargs -p being the simplest example.)   Don’t re-invent something that has already been well done.


In reply to Re: [Thread::Queue] How to handle unexpected termination and time out in threads by sundialsvc4
in thread [Thread::Queue] How to handle unexpected termination and time out in threads by oobobe

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (18)
    As of 2014-10-22 14:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (118 votes), past polls