>>>>> "RN" == Ranga Nathan <[EMAIL PROTECTED]> writes:
RN> I used this module to create a simple server. The server I need
RN> simply accepts some data and drops it into an MQ queue (not my
RN> choice!) and returns a confirmation. When testing this, I found
RN> that only one client was getting response. Other clients could
RN> send but not receive. When the first client terminated, then the
RN> second client got a lot of responses. As suspected, the server was
RN> 'blocking'. According to perldoc, if type is set to 'select',
RN> sometimes it may block when there is a lot of input. In my case
RN> there was only minimal input.
i have just browsed this module and it seems to not support asynchronous
i/o properly. the bug you mention is that it doesn't check if it can
write to a client. so if it writes too much and fills the socket buffer
and the client is blocked for some reason, this will block the entire
server which is probably what you are seeing.
RN> Exact wording....
RN> "The select-based server may block on i/o on a heavily loaded system. If
RN> you need to do non-blocking i/o you should look at
RN> NetServer::FastSelect."
i can't find that module on cpan.
RN> I could set the server type to 'forking' or try the FastSelect.. but I
RN> would like to know if 'select' would necessarily block regardless of
RN> amount of traffic.
select isn't the problem. the issue is how the module uses it and
whether it handles real multiplexing I/O.
<plug time>
here is a simple stem based server which does full async i/o on multiple
ports with delayed times between results. it is part of a scaffold i
wrote for a talk i am giving at oscon, 'parallel sessions in perl'. this
is purely event driven and will never block. and i think the code is
very clean and neat given how much it really is doing. it can easily be
modified to do what you want. it is based on stem .11 beta and i have to
upload that to my site. if you want to use this let me know and i will
get you the url and the latest snapshot that supports this. the shutdown
and write_final features are very new enhancements. you can do regular
writes and regular reads with the stem::asyncio module if you want and
detect socket closed with the the async_closed method.
i don't think you could get a much simpler server than this. it is only
4 subs (methods) and it does multiple socket listening, fully async and
buffered i/o with multiple clients and with custom delays.
but hey, what do i know? :) (this scaffold is still under dev which is
why the ports are hardwired. arg parsing and cleanups to be done
soonish).
thanx,
uri
#!/usr/local/bin/perl -w
use strict ;
use Stem ;
use Stem::Socket ;
use Stem::AsyncIO ;
use Time::HiRes qw( time ) ;
my $port1 = 8888 ;
my $port2 = 8889 ;
my $time ;
my $listen1 = Stem::Socket->new(
object => bless ( {
id => 'upper'
}, __PACKAGE__ ) ,
port => $port1,
server => 1,
) ;
die "can't listen on $port1: $listen1" unless ref $listen1 ;
my $listen2 = Stem::Socket->new(
object => bless ( {
id => 'reverse'
}, __PACKAGE__ ),
port => $port2,
server => 1,
) ;
die "can't listen on $port2: $listen1" unless ref $listen2 ;
Stem::Event::start_loop() ;
exit ;
sub connected {
my( $obj, $socket ) = @_ ;
my $self = bless {
socket => $socket,
id => $obj->{id},
}, __PACKAGE__ ;
my $async = Stem::AsyncIO->new(
object => $self,
fh => $socket,
send_data_on_close => 1,
) ;
ref $async or die "can't create Async: $async" ;
$self->{async} = $async ;
}
sub async_read_data {
my( $self, $data ) = @_ ;
print "READ [$$data]\n" ;
$self->{'data'} = ${$data} ;
# my $delay = .5 ;
my $delay = rand( 1 ) + .5 ;
#print "DELAY $delay\n" ;
$time = time() ;
my $timer = Stem::Event::Timer->new(
object => $self,
delay => $delay,
) ;
ref $timer or die "can't create Timer: $timer" ;
$self->{timer} = $timer ;
return ;
}
sub timed_out {
my( $self ) = @_ ;
my $delta = time() - $time ;
printf "DELTA = %6f\n", $delta ;
my $data = $self->{data};
my $echo_data = $self->{'id'} eq 'upper' ?
uc( $data ) : reverse( $data ) ;
#print "ECHO [$echo_data]\n" ;
$self->{async}->final_write( $echo_data ) ;
}
sub async_closed {
my( $self ) = @_ ;
print "CLOSED $self\n" ;
}
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm