This creates server and client sockets in separate threads--though the threading is not a factor in the problem--and the client repeatedly connects; send a packet; receives a packet; and then disconnects before repeating.

Initially on my system, this runs smoothly at around 500 connects/second, but somewhere usually between 8000 and 16000 cycles, it just grinds to a halt. And stays that way for an extended period before suddenly starting to run again and then freezing again.

This appears to be a problem with the tcpip subsystem as there are lots of open connections hanging around during the freeze periods that are in the SYN_SENT state.

Questions:

  1. Is this unique to my 5.10.1 64-bit Perl, Vista 64-bit system?
  2. Unique to windows?
  3. Caused by something I am doing?
  4. Or something I'm not doing?
  5. Is there a cure?

Thanks for any pointers.

Updated code to remove Win32 dependency; and ditched the stack size arg (just in case).

#! perl -slw use strict; use Time::HiRes qw[ time usleep ]; use threads; use threads::shared; use IO::Socket; our $port //= 12345; my $svrN :shared = 0; my $clientN :shared = 0; my $start = time; async { my $svr = IO::Socket::INET->new( Listen => SOMAXCONN, Reuse =>1, LocalPort => $port, Timeout => 0.1, ) or die $!; while( my $client = $svr->accept ) { my $in = <$client>; print $client "echod:$in"; $client->shutdown( 2 ); close $client; ++$svrN; } }->detach; async { while( 1 ) { my $svr = IO::Socket::INET->new( PeerHost => 'localhost', PeerPort => $port, Reuse => 1, Timeout => 0.1, ) or usleep( 10_000 ), next; sleep 0; print $svr ++$clientN; my $echo = <$svr>; sleep 0; $svr->shutdown( 2 ); close $svr; sleep 0; } }->detach; $|++; while( usleep 100_000 ) { printf "\rserver:$svrN client:$clientN cycles: %.3f/sec", $svrN / ( time() - $start ); } __END__ c:\test>junk79 -port=12347 server:9565 client:9565 cycles: 503.421/sec ## some time later server:16305 client:16305 cycles: 397.683/sec ## some time later still server:16305 client:16305 cycles: 267.295/sec

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.

In reply to Socket hang. (Windows or Perl? Solutions?) (Updated) by BrowserUk

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!
  • 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, details, 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, summary, 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.