Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

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

Okay. I think I have a handle on what is happening. The short explanation is that you are simply running the OS out of resources.

2000 concurrent threads, each starting a console session doing a dir -- 100 of which are recursive from root -- consumes prodigious amount of resources.

Your use of a VM maybe a contributory factor; I cannot reproduce the error here. My system grinds to a near complete halt for an extended period, but once the 1900 dirs of the current directory finish and 1900 cmd.exe's & 1900 threads & 1900 tcp connections go away, my system returns to a responsive state and it is then just a case of waiting while the 100 dir/s c:\ finish recursing the 212,000 directories and 1.5 million files on my hard drive, and then for all that data to get wrapped up in your protocol, shipped back to the receiving processes, unwrapped and output to the terminal.

But it works. It eventually completes okay; which I find quite remarkable and makes me think Ithreads -- on windows at least -- is in remarkably good fettle.

I do not believe that the problem you are seeing is a Perl issue; but rather an OS issue where -- under extreme resource depletion -- it is dropping/forgetting kernel thread objects that have completed before perl gets the chance to wait for them. I don't believe that should happen under normal circumstances, but these are not normal.

Why "believe" this and "believe" that!

There is a possibility that the trace output we produced is lying to me. For simplicity, the trace I had you add to threads.xs is crude -- and flawed. Using printf from multiple threads in C, is subject to the same problems of buffering and overlapping as print/printf are from multiple threads in Perl. It needs to be serialised. It is possible the symptoms I am seeing in the trace output you supplied -- Ie. A thread created that has become a non-thread by the time Perl tries to join it:

9408: ITCREATE: thread handle:2ca0 thread-id: 3620x ... thread handle:2ca0 thread-id: 0x GetLastError output: '6'

Is a symptom of overwritten buffered IO, rather than an OS "quirk". To counter that possibility, I've re-written the tracing code and wrapped it in a critsec to (attempt to) preclude that possibility. What that means is I am going to ask you to replace your threads.xs with this version:

I was going to post it above, but it is too big; perlmonks won't accept it. You'll need to /msg me an email ID so I can send it to you.

And re-build/install it. Then re-create your problem one more time. If the new install goes well, you should see:

*** CritSec initialised *** RXD+ had been started on port 1600 ...

when you start rxd.pl.

If you are successful in re-creating the failure, the trace output should be more reliable.

I also suggest the following 1-line change to rxd.pl which whilst it won't cure the problem; should make it less likely to occur -- assuming I've diagnosed the problem correctly. The change is to severely reduce the stack size allocated to each thread:

use warnings; use threads stack_size => 4096; use threads::shared; use IO::Handle; use IO::Socket::INET; use File::Find; use File::Path; use Digest::SHA; ...

Note: Anecdotal evidence suggest that this does not work under (some versions of) *nix. If that is one of your targets. (It might work with 64k rather than 4k, but that is a guess! I've never had any feedback to confirm or deny that.)

A long term fix

Finally, I think that the real fix for the problem -- assuming we can confirm my diagnosis -- is to limit the number of concurrent clients to some sane number. On windows, with the stack_size fix above, a moderately specified VM -- say 8GB memory -- should handle 100 concurrent clients okay. You'll need to tweak that number for your target environment.

How I would implement that limiting is in the following code:

... unless ($client = $lsn->accept) { tprint ("Could not connect to socket: " . $!); next; } if( threads::list( threads::running >= 100 ) { $client->shutdown( 2 ); $client->close; tprint( "Client $client rejected; too many concurrent clients. +" ); next; } ...

You might want to defer the rejection until you've accepted and validated the transmitted command and return a rejection/retry notification at that point if there are still too many concurrent clients.

{Thwack!} Balls in your court :)

Update: BTW, I also reduce testrdx.pl to this:

Which both reduced system resource usage (by doing away with the threads waiting on clients) on my single machine tests and control the number of concurrent clients.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong


In reply to Re^9: PANIC: underlying join failed threded tcp server by BrowserUk
in thread PANIC: underlying join failed threded tcp server by rmahin

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: (14)
    As of 2014-12-26 16:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (172 votes), past polls