Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

mod_perl installed but not faster

by true (Pilgrim)
on Oct 18, 2002 at 10:22 UTC ( [id://206256]=perlquestion: print w/replies, xml ) Need Help??

true has asked for the wisdom of the Perl Monks concerning the following question:

I've installed the mod_perl.c module on an apache 1.3.6 rh6.2 box. I added the Location tag in my httpd.conf file. From the looks of eveything mod_perl is installed and in the game. My httpd.conf file has the following.

# If the perl module is installed, this will be enabled. <IfModule mod_perl.c> Alias /perl/ /home/httpd/perl/ <Location /perl> SetHandler perl-script PerlHandler Apache::Registry Options +ExecCGI </Location> </IfModule>
I duplicated the following script in order to test the mod_perl for speed.
#!/usr/bin/perl -w $|=1; use strict; use LWP::Simple; use Time::HiRes; print "Content-type:text/html\n\n"; print "\n\n<pre>"; print Time::HiRes::time()."\n"; my $cd;my $z; my $st = Time::HiRes::time(); for($z=0; $z < 10;$z++){ my $ast = Time::HiRes::time(); my $get = get "http://www.perl.to/index.cgi?a=".$z; my $aed = Time::HiRes::time(); print "$z(".($aed-$ast).")\n"; } print "$cd\n"; my $ed = Time::HiRes::time(); print "took=".($ed-$st)."</pre>";
One copy of the script above went in my mod_perl folder (/home/httpd/perl/). It ran from a web browser. mod_perl ON
The other went to a Virtual Domain folder on the same server. It can be seen at. mod_perl OFF Both scripts work. My error_logs are quiet when i test them. My question is, why isn't my mod_perl faster?
Does anyone know of a way to verify, within a perl script, the status of mod_perl? I notice that the Content-type header is visible in the mod_perl test from the browser. Doesn't that tell me it's working?
- Advice encouraged
jtrue

P.S. perl -v = version 5.005_03

Replies are listed 'Best First'.
Re: mod_perl installed but not faster
by ajt (Prior) on Oct 18, 2002 at 10:55 UTC

    A Perl script runs at the same speed independent of the interpretor's location: embedded (mod_Perl) or external (CGI). As Perl is big and can be slow to load via CGI, it's by avoiding this (Perl loads only once when you start Apache) that mod_Perl gains it's speed advantage.

    If you want to load and run many small Perl sctipts then mod_Perl will make a huge difference. If you want to load and run only a few long running scripts then CGI is probably good enough.

    There are other advantages to mod_Perl, for example you can get at the innards of Apache from Perl, but with this and other advantages comes complexity.

    Unless I miss understand what you are doing, you are only timing the script in action, not the time to start the script and run it. Which is why they take the same amount of time to run, but the mod_perl one should start faster.

    I hope you plan to upgrade Apache, the version you quote is a we bit old and there are know security problems with it. Actually, I think the same can be said of RH6.2.

    Update: If you are curious about mod_Perl is then also look here:


    --
    ajt

      Yes, i was trying exactly that. I wanted to time the script in action. I was hoping the multiple requests into my virtual server would be served faster. (Both scripts are on the same server). Perhaps i should try and http get another script inside of the mod_perl folder. Hopefully that would prove faster. Thanks for your ideas! It does seem like it is installed correctly, i just need to learn how to harness it.

      BTW, The Apache security hole in 1.3 is patchable. i'm pretty happy with 6.2, it's old, but stable :o My secondary drive is 7.2 though, i am curious to see the differences between the two avec mod_perl.

        I did this and am now seeing a big increase in speed! By requesting a local HTTP request with mod_perl i was able to save 30 seconds for 500 LWP requests. I was also able to use $ENV{'MOD_PERL'} to verify my mod_perl install (mod_perl/1.23).
        The test: i did a Simple get for a virtual domain on my server This was a local request, through apache. I requested this test page 500 times. One loop ran without mod_perl, the other with mod_perl.
      • Without mod_perl the test took=35.6595680713654 seconds
      • With mod_perl the test took=5.24513804912567 seconds
      • A few more runs confirmed my results. Thanks PM world. Without this resource, mod_perl would have remained a mystery to me. Props to ajt for all the pointers.
Re: mod_perl installed but not faster
by shotgunefx (Parson) on Oct 18, 2002 at 10:42 UTC
    Well off the top of my head, you're performing an HTTP fetch from another server which is most likely where all the time is spent so the overhead of forking a process and loading perl probably doesn't add up to much.

    It's like driving behind a blue haired lady, It doesn't matter if you're in a Diablo or a Dart, you'll still be doing 15 MPH.

    -Lee

    "To be civilized is to deny one's nature."
      I specified in my node that Both scripts exist on the same server. I was hoping to test the speed of mod_perl as well as multiple requests through apache. that's why i did a simple fetch 10 times.
        mod_perl with Apache::Registry is only saving you the compilation time (compiling source/loading modules).

        The compilation and execution of your script compared to the fetch (opening a socket, sending the request, connecting, waiting for the server to fork, starting perl, compiling, executing and sending response) is a relativly small amount of time. If index.cgi is a slow script then it just makes the comparison even more moot.

        A better benchmark might be a script that contains a large data structure, lots of modules or simple parses a CGI request and prints a response.

        -Lee

        "To be civilized is to deny one's nature."
Re: mod_perl installed but not faster
by tomhukins (Curate) on Oct 18, 2002 at 10:49 UTC
    See the MOD_PERL environment variable described in the mod_perl documentation. Also, if you type mod_perl into the search box at the top of each page, you will find many previous discussions here that might help such as Getting started with mod_perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://206256]
Approved by George_Sherston
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2024-04-19 09:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found