in reply to thread failed to start?

Modified my code in previous reply, now both server and clients reside in a single process. This makes the threading structure a little bit more complex. Don’t think this should replace the previous version of code, because of the architecture difference, so just create this new reply.

Also added yield() to all threads.

Code is tested.

use strict; use IO::Socket; use threads; use threads::shared; my $numClients = shift; my $all_created : shared = 0; $| = 1; threads->create(\&server); print "Creating $numClients clients...\n"; for (1..$numClients) { my $socket = IO::Socket::INET->new(Proto => "tcp", PeerAddr => "lo +calhost", PeerPort => 7001) || print "Socket creation error: $!\n"; threads->new(\&client, $socket, $_)->detach; print "."; } print "\nAll Created\n"; sleep 1; $all_created = 1; <STDIN>; sub server { my $server = new IO::Socket::INET(Proto => "tcp", LocalPort => 700 +1, Listen => 5) || die "failed to establish socket\n"; while (1) { my $client = $server->accept; threads->create(\&client_handle, $client); threads->yield; } } sub client_handle { my $client = shift; while (<$client>) { chomp; print $client $_ + 1, "\n"; threads->yield; } } sub client { my ($socket,$id) = @_; sleep 1 while (!$all_created); print $socket "1\n"; while (<$socket>) { chomp; print "$id <<== $_\n"; print $socket $_ + 1, "\n"; threads->yield; sleep 5; } return; }

Replies are listed 'Best First'.
Re: Re: thread failed to start?
by Anonymous Monk on Mar 12, 2003 at 17:53 UTC
    pg,

    I have done a whole bunch of testing. All with perl 5.8 under both linux and win2k,usually one as the client and the other as the server.

    I've used my code, and your first code above. You're right, everything is working fine at 100. The hard stop seems to be at 110. Or actually it might be 113.

    With win2k as the server, I get all kinds of 'connection refused' errors. Of course then I get all kinds of errors. Sometimes it has seemed to help to set Listen=>50 or something higher anyway. .

    With linux as the server and generating 120 clients from win2k, all connections seem to occur, however only the first 110 clients ever talk. I read some where that under windows there is a main thread and a thread for 'use threads' and a thread for 'use threads::shared'. Those 3 plus the 110 clients that talk = 113.

    Throughout the other various test I have run, the numbers 110 or 113 keep cropping up as the limits. So apparently there is something built in that I cannot control as far as the number of simultaneous connections goes.

    Of course this is very discouraging as I will now need to look around for another language to use to get a stress tester built. It pains me as I promote perl around here and now I'm not looking too good on this one. :-(

    If you have any other ideas that I can try, please let me know. I have even tried using arrays of IO::Select objects without threading, no go.

    Thanks for all your help!!

    Joel

Re: Re: thread failed to start?
by deadkarma (Monk) on Mar 13, 2003 at 18:58 UTC
    You don't need to create more than one server socket if you Reuse

    you can:

    my $server = new IO::Socket::INET( Proto => "tcp", LocalPort => 7001, Listen => 5, Reuse => 1) || die "failed to establish socket\n";
    And then accept in the thread.