You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Udlei Nattis <ma...@anankeit.com.br> on 2002/07/16 20:55:55 UTC

while - modperl 2.0/Apache 2.0

hi

sorry my english
i have one problem
when i open 2 browsers intance and access my perl script
instance 1 run script OK
instance 2 waiting instance 1 finalize to run :/

i need run simultane 2 instance
(modperl 2.0 dev 5 / perl 8 rc 3 / apache 2.0 prefork or worker )

example:

#!/usr/bin/perl

use Apache2;
$| = 1;
my $r = Apache->request;
$r->content_type("text/html");
$r->send_http_header;
$r->print(Apache::get_server_version()."<br>");

# only for Apache Pre-Fork MPM
#if (Apache::MPM_IS_THREADED) {
#   my $id = APR::OS::thread_current();
#       print "current thread id: $id";
#}
#else {
#       print "current process id: $$";
#}

$i = 0;
while ($i < 20) {
        $r->print($i."<br>\n");
        $i++;
        sleep 1;
}

thanks

Udlei Nattis
www.nobol.com.br


Re: while - modperl 2.0/Apache 2.0

Posted by Udlei Nattis <ma...@anankeit.com.br>.
thanks ;)

now i understand
to run in others browser instances you need change url
example:
http://127.0.0.1/hello-world?a
http://127.0.0.1/hello-world?b
http://127.0.0.1/hello-world?c
http://127.0.0.1/hello-world?d

/tmp/test123
1505: 162 <- thread
1505: 155 <- thread
1578: 146
1505: 131 <- thread
1578: 124
1505: 163  <- thread
1505: 156  <- thread
1578: 147
1505: 132

:))))))))))))))))))

bye

nattis

Stas Bekman wrote:

> ok, looks like your setup is fine.
>
> Though I cannot seem to reproduce your problem. Indeed it seems that 
> the unbuffered output doesn't work. I'm checking on that. But I've 
> devised a better test that verifies that the requests aren't 
> serialized. If you run this hander by two clients at the same time, 
> you should see the lines in /tmp/test123 being interleaved by two 
> processes. If this doesn't happen and you get first 100 lines from 
> process A followed by process B's 100 lines than indeed we have a problem.
>
> sub handler {
>     my $r = shift;
>     $r->content_type('text/plain');
>     local $| = 1;
>
>     open my $fh, ">>", "/tmp/test123" or die $!;
>     my $oldfh = select($fh); local $| = 1; select($oldfh);
>     my $i = 0;
>     while ($i < 100) {
>       $r->print("$$: $i \n");
>       print $fh "$$: $i \n";
>       sleep 1;
>       $i++;
>     }
>
>     $r->print(__PACKAGE__);
>     close $fh;
>
>     return Apache::OK;
> }
>
> If this indeed doesn't work, please try the suggestion at:
> http://perl.apache.org/docs/1.0/guide/debug.html#Using_the_Perl_Trace
> so you can see where the second process is stalled. If you don't get 
> anything from this approach try to attach to the second process with 
> gdb and see where it is stack on the C calls level. Though I suggest 
> that you test with prefork and this setup:
>
> <IfModule prefork.c>
> StartServers         2
> MinSpareServers      2
> MaxSpareServers      2
> MaxClients           2
> MaxRequestsPerChild  0
> </IfModule>
>
> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
>
>
>




Re: while - modperl 2.0/Apache 2.0

Posted by Stas Bekman <st...@stason.org>.
ok, looks like your setup is fine.

Though I cannot seem to reproduce your problem. Indeed it seems that the 
unbuffered output doesn't work. I'm checking on that. But I've devised a 
better test that verifies that the requests aren't serialized. If you 
run this hander by two clients at the same time, you should see the 
lines in /tmp/test123 being interleaved by two processes. If this 
doesn't happen and you get first 100 lines from process A followed by 
process B's 100 lines than indeed we have a problem.

sub handler {
     my $r = shift;
     $r->content_type('text/plain');
     local $| = 1;

     open my $fh, ">>", "/tmp/test123" or die $!;
     my $oldfh = select($fh); local $| = 1; select($oldfh);
     my $i = 0;
     while ($i < 100) {
       $r->print("$$: $i \n");
       print $fh "$$: $i \n";
       sleep 1;
       $i++;
     }

     $r->print(__PACKAGE__);
     close $fh;

     return Apache::OK;
}

If this indeed doesn't work, please try the suggestion at:
http://perl.apache.org/docs/1.0/guide/debug.html#Using_the_Perl_Trace
so you can see where the second process is stalled. If you don't get 
anything from this approach try to attach to the second process with gdb 
and see where it is stack on the C calls level. Though I suggest that 
you test with prefork and this setup:

<IfModule prefork.c>
StartServers         2
MinSpareServers      2
MaxSpareServers      2
MaxClients           2
MaxRequestsPerChild  0
</IfModule>

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: while - modperl 2.0/Apache 2.0

Posted by Udlei Nattis <ma...@anankeit.com.br>.
Udlei Nattis wrote:

how many servers do you run?
worker:
<IfModule worker.c>
StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>

prefork:
<IfModule prefork.c>
StartServers         5
MinSpareServers      5
MaxSpareServers     10
MaxClients         150
MaxRequestsPerChild  0
</IfModule>

now i change my styles lines
i using:

package Apache::HelloWorld;

#LoadModule perl_module modules/mod_perl.so
#PerlSwitches -Mlib=modperl-2.0/examples/lib

##optional
#PerlModule Apache2
#PerlModule Apache::compat

#<Location /hello-world>
#    SetHandler modperl
#    PerlResponseHandler Apache::HelloWorld
#</Location>

use strict;
use Apache::RequestRec (); #for $r->content_type
use Apache::RequestIO ();  #for $r->puts
use Apache::Const -compile => 'OK';
$| = 1;

sub handler {
     my $r = shift;
     $r->content_type('text/plain');

     #send_http_header API function does not exist in 2.0

     my $i = 0;
     while ($i < 10) {
       $r->print($i."\n");
       sleep 1;
       $i++;
     }

     $r->puts(__PACKAGE__); #print not yet implemented

     return Apache::OK;
}

1;


and problem persist
instance 1 run ok
instance 2 waiting intance 1 finalize

thanks

nattis
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com






Re: while - modperl 2.0/Apache 2.0

Posted by Stas Bekman <st...@stason.org>.
Udlei Nattis wrote:
> hi
> 
> sorry my english
> i have one problem
> when i open 2 browsers intance and access my perl script
> instance 1 run script OK
> instance 2 waiting instance 1 finalize to run :/
> 
> i need run simultane 2 instance
> (modperl 2.0 dev 5 / perl 8 rc 3 / apache 2.0 prefork or worker )

how many servers do you run? Are you testing this in the single server 
mode? Seems that you run only one server or only one process with one 
thread.

a few comments regarding the code (irrelevant to your problem):

> #!/usr/bin/perl
> 
> use Apache2;

this should go into startup/httpd.conf.

> $| = 1;
> my $r = Apache->request;

that should be just:

my $r = shift;

since your code is wrapped into sub handler { }.

what you are doing is expensive under threads.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com