I have not been a real fan of Apache::Request and so haven't used it, but 
23% does seem like a big difference.

Of course, if there is an initial hit in terms of parsing the incoming 
parameters in Perl versus C, then that would tend to be a fixed computation 
whose effect in slowing down the script would go down quite a bit during 
normal script operation. Since getting data out of the parameters (once 
parsed) should be computationally inexpensive.

Can you take out the print statement at the end that goes through the 
parameters and just print "Hello world" instead and see if the difference 
is still 23%... If it is, when we can assume that this is the primary 
slowdown and one that could be resolved if Lincoln Stein (or someone else) 
were to code a CGI.pm wrapper around Apache::Request that simply uses it 
for the core calls and calls CGI.pm for HTML generation type of calls.

In advance I have to say that I am still a bit biased towards the use of 
CGI.pm and Apache::Registry because I hate writing scripts that can only be 
used on one platform. To me, I am interested in finding out if there are 
some clean ways of making it possible for me not to write something 
proprietary to mod_perl and still not get embarressed by the speed. :)

Thanks,
     Gunther

At 05:48 PM 4/15/00 +0300, Stas Bekman wrote:
>Well, Gunther has pointed out that the benchmark has been unfair, since
>CGI.pm's methods have not been precompiled. I've also preloaded both
>scripts this time to improve numbers and unloaded a system a bit while
>running the tests. Here is the corrected version:
>
>=head1 Benchmarking CGI.pm and Apache::Request
>
>Let's write two registry scripts that use C<CGI.pm> and
>C<Apache::Request> to process the form's input and print it out.
>
>   benchmarks/cgi_pm.pl
>   --------------------
>   use strict;
>   use CGI;
>   my $q = new CGI;
>   print $q->header('text/plain');
>   print join "\n", map {"$_ => ".$q->param($_) } $q->param;
>
>   benchmarks/apache_request.pl
>   ----------------------------
>   use strict;
>   use Apache::Request ();
>   my $r = Apache->request;
>   my $q = Apache::Request->new($r);
>   $r->send_http_header('text/plain');
>   print join "\n", map {"$_ => ".$q->param($_) } $q->param;
>
>We preload both modules that we ought to benchmark in the
>I<startup.pl>:
>
>   use Apache::Request ();
>   use CGI  qw(-compile :all);
>
>We will preload the both scripts as well:
>
>   use Apache::RegistryLoader ();
>   Apache::RegistryLoader->new->handler(
>               "/perl/benchmarks/cgi_pm.pl",
>    "/home/httpd/perl/benchmarks/cgi_pm.pl");
>   Apache::RegistryLoader->new->handler(
>               "/perl/benchmarks/apache_request.pl",
>    "/home/httpd/perl/benchmarks/apache_request.pl");
>
>Now let's benchmark the two:
>
>   % ab -n 1000 -c 10 \
>
>'http://localhost/perl/benchmarks/cgi_pm.pl?a=b&c=+k+d+d+f&d=asf&as=+1+2+3+4'
>
>   Time taken for tests:   23.950 seconds
>   Requests per second:    41.75
>   Connnection Times (ms)
>                 min   avg   max
>   Connect:        0     0    45
>   Processing:   204   238   274
>   Total:        204   238   319
>
>   % ab -n 1000 -c 10 \
>
>'http://localhost/perl/benchmarks/apache_request.pl?a=b&c=+k+d+d+f&d=asf&as=+1+2+3+4'
>
>   Time taken for tests:   18.406 seconds
>   Requests per second:    54.33
>   Connnection Times (ms)
>                 min   avg   max
>   Connect:        0     0    32
>   Processing:   156   183   202
>   Total:        156   183   234
>
>Apparently the latter script using C<Apache::Request> is about 23%
>faster. If the input is going to be larger the speed up in per cents
>grows as well.
>
>Again this benchmark shows that the real timing of the input
>processing, when the script is much heavier the overhead of using
>C<CGI.pm> can be insignificant.
>
>______________________________________________________________________
>Stas Bekman             | JAm_pH    --    Just Another mod_perl Hacker
>http://stason.org/      | mod_perl Guide  http://perl.apache.org/guide
>mailto:[EMAIL PROTECTED]  | http://perl.org    http://stason.org/TULARC/
>http://singlesheaven.com| http://perlmonth.com http://sourcegarden.org
>----------------------------------------------------------------------

__________________________________________________
Gunther Birznieks ([EMAIL PROTECTED])
Extropia - The Web Technology Company
http://www.extropia.com/

Reply via email to