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:
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
In reply to Socket hang. (Windows or Perl? Solutions?) (Updated) by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |