You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Matthew <ma...@matthewboehm.com> on 2006/06/23 01:04:12 UTC

CGI better than MP?

How could a CGI using ModPerl::Registry be faster than a Perl-Script 
running under mod_perl?  When I say 'faster', I'm talking a few tenths 
of a second to half a second using Apache Benchmark (ab).

What really gets the water boiling is that the CGI is coded 'worse' (ie: 
no strict, no warning, every var a global var, etc..). CGI even has a 
require on tools.pl, so total CGI is 1347 lines.  module is 952 lines.

CGI is not using DBI, nor ApacheDBI (its using some older mysql module). 
  CGI is even using 3 extra modules that MOD is not.

sniplets of my httpd.conf:
----------------------------------
StartServers            10
MinSpareServers         10
MaxSpareServers         15
MaxClients              150
MaxRequestsPerChild     500

PerlRequire     /home/drmac/public_html/secconf/startup.pl

<Location /pages/sc2/roomlogin>
         SetHandler              perl-script
         PerlResponseHandler     testPkg::v2
	# This matches
	# http://www.mydomain.com/pages/sc2/roomlogin?roomID=3
</Location>

<Directory /home/drmac/public_html/pages/sc2/>
         Options +ExecCGI

	# This matches
	# http://www.mydomain.com/pages/sc2/roomlogin.cgi?roomID=3
         <FilesMatch "\.cgi$">
                 SetHandler perl-script
                 PerlResponseHandler ModPerl::PerlRun
                 PerlOptions +ParseHeaders
         </FilesMatch>
</Directory>
--------------------------------------

Proof is in the puddin':

	5 Trials each of "ab -c 2 -n 500"

<restarted apache>
Trial 1 CGI - 2.9265
Trial 2 CGI - 1.8933
Trial 3 CGI - 2.1517
Trial 4 CGI - 2.4451
Trial 5 CGI - 1.9838

<restarted apache>
Trial 1 MOD - 2.8199
Trial 2 MOD - 2.9183
Trial 3 MOD - 2.8225
Trial 4 MOD - 2.7791
Trial 5 MOD - 2.2639

At least the module is consistent in its performance. The CGI outputs 
5378 bytes and the MOD outputs 5343, if that makes a difference.

Just ran "ab -c 5 -n 1000" once on each and CGI still beat MOD by 0.6 
seconds.

Frustrated...
-Matthew

Re: CGI better than MP?

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2006-06-22 at 18:04 -0500, Matthew wrote:
> What really gets the water boiling is that the CGI is coded 'worse' (ie: 
> no strict, no warning, every var a global var, etc..).

There must be something in your new code that is coded in a way that
makes it slow.  A profiler like Apache::DProf is the way to find the
slow part.

> sniplets of my httpd.conf:
> ----------------------------------
> StartServers            10
> MinSpareServers         10
> MaxSpareServers         15
> MaxClients              150
> MaxRequestsPerChild     500

Do you really have enough memory to run 150 apache processes with
mod_perl loaded?  Most people don't.

> <restarted apache>
> Trial 1 CGI - 2.9265
> Trial 2 CGI - 1.8933
> Trial 3 CGI - 2.1517
> Trial 4 CGI - 2.4451
> Trial 5 CGI - 1.9838

Those numbers are too inconsistent to draw any meaningful conclusions.
My guess is that you may be driving the machine into swap here or
choking some other resource like your database.

> Just ran "ab -c 5 -n 1000" once on each and CGI still beat MOD by 0.6 
> seconds.

If you were able to run the same code under Registry and as a handler, I
would expect the handler to be very slightly (a tenth of a second or
less) faster.  In this test though, you're really just measuring the old
code vs. the new code.

- Perrin