Re: Handling multiple FastCgi connections with one process(without multithreading)
"Bruno Granatowicz" <[email protected]>
| Newsgroups | gmane.comp.web.fastcgi.devel,gmane.spam.detected |
|---|---|
| Message-ID | <[email protected]> |
Hi, Seems like I have the same problem. Anyone knows the solution. Thanks a lot! Bruno "Sebastian Boehm" <[email protected]> wrote in message news:4EE8B42F-1A05-40DF-8CB0-5895F62F4447-k4s9CpUdQt4MN+8nz9vMXQ@public.gmane.org Hi, I want to handle multiple (~10) long running requests with one perl script. I want to use it under apache. I wrote a small proof-of-concept script to see whether that works. With the script I attached I was able to handle two requests in parallel. But why not more ? With that script I have two browser windows counting 1..10 (the select () blocks for 1sec, so it counts in 1sec steps). On the server runs only 1 process of this script. So I verified that it handles two requests in parallel. But If I do a third request, it waits for one of the two first requests to finish and then the processing of the third request begins. When the first and the second requests arrive, select() returns 1. When the third request arrives select returns 0 (after timed out), but when one of the two initial requests finish select returns 1, so the processing of the third request begins. Can someone look over that script and help me here ? (If there is some other hint you can give me regarding this topic I would appreciate it) (I tried the pure-perl version of FCGI.pm also, with no difference, does mod_fastcgi limit this ? ) Thank you very much ! /sebastian --script : ---- #!/usr/bin/perl use strict; use FCGI; use Fcntl; use POSIX qw(:errno_h); use IO::Handle; my @fcgihandles = (); #create a couple of request objects for(1..10) { push @fcgihandles,create_fcgi_handle($_) } while(1) { # wait one second for new request my $rbits = ''; vec( $rbits, 0 , 1 ) = 1; #fcgi socket has fileno 0 my $nfound = select ($rbits, undef, undef, 1); # if there is a new connection accept it if($nfound >0) { foreach my $handle (@fcgihandles) { next if $handle->{'status'} ne 'available'; if($handle->{'req'}->Accept() >= 0) { my $out = $handle->{'out'}; print $out "Content-type: text/html\r\n\r \n<html><body>BEGIN ".$handle->{'id'}."<br/>\r\n"; $handle->{'req'}->Flush(); $handle->{'xy'}=1; $handle->{'status'}='accepted'; last; } else { warn 'under which circumstances does this happen?'; } } } foreach my $handle (@fcgihandles) { next if $handle->{'status'} ne 'accepted'; my $out = $handle->{'out'}; print $out "line:".$handle->{'xy'}."<br/>\r\n"; $handle->{'req'}->Flush(); $handle->{'xy'}++; if($handle->{'xy'}==10) { print $out "finished </body></html>\r\n"; $handle->{'req'}->Flush(); $handle->{'req'}->Finish(); $handle->{'status'}='available'; } } } sub create_fcgi_handle($) { my $id = shift; my %data = (); my %env = (); my $in = new IO::Handle; my $out = new IO::Handle; my $err = new IO::Handle; my $req = FCGI::Request($in,$out,$err, \%env); $in->autoflush(1); $out->autoflush(1); $out->autoflush(1); $data{'id'} = $id; $data{'in'} = $in; $data{'out'} = $out; $data{'err'} = $err; $data{'env'} = \%env; $data{'req'} = $req; $data{'status'} = 'available'; return \%data; } ___________________________________ fastcgi-developers mailing list http://fastcgi.com/fastcgi-developers/ ___________________________________ fastcgi-developers mailing list http://fastcgi.com/fastcgi-developers/