On 08/28/2014 09:19 AM, Chris Knipe wrote:
Hi All,
I’ve looked at Net::Server (and have my “new” server with some 20K lines
of code written in it that we’re currently finalising), POE, and a few
other things, but I cannot find what I am looking for… I’m hoping for
some assistance / pointers please. I am looking for the following
simple scenario…
On the server side, read data through the socket (for simplicity, let’s
say “commands” are terminated by \n)
On the client side, send numerous commands to the server, WITHOUT
waiting for a response – that’s simple enough.
Now, let’s say the server sleep($randomtime) between commands to
simulate a work load. I effectively want the following
C> Do 1
C> Do 2
S> Done 1
C> Do 3
C> Do 4
S> Done 4
S> Done 2
S> Done 3
I know this sounds simple, but can anyone give a rough example of the
server code (even if it’s just an echo with a random sleep). For the
love of… I cannot seem to stop the synchronous nature of POE, or
Net::Server. The whole wait for input, deal with input, write output
thing is really blocking my application’s performance, seriously, at
this point in time. I need to be truly asynchronous.
I need to also preferably need to use PreForks. The application needs
to deal with some 500Mbps in terms of bandwidth on the sockets, and a
good amount of thousands of concurrent connections. Again, I’m not sure
whether Net::Server will scale (we’re developing / debugging currently,
whilst in production we currently use xinetd).
Many thanks,
Chris.
Are you saying the normal 'unix' way won't work? (ie. listen on socket,
fork on an accepted connection, do the work, close)
$server = IO::Socket::INET->new(LocalPort => 8801,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 10)
or die "Server open failed: $!\n";
while(1){
#accept() will block until connection received
$client = $server->accept();
#create new process for client
my $pid = fork();
if($pid == 0){
processClient($client);
}
else{
close($client);
waitpid(-1,WNOHANG);
}
}
--Sam
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/