You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Doug MacEachern <do...@pobox.com> on 2000/02/17 01:39:45 UTC

Re: Slight performance enhancement for dynamic sites.

On Wed, 2 Feb 2000, Steve Reppucci wrote:

> 
> Here's a tiny performance tweak that I stumbled across that I don't
> believe I've seen in any of the other online docs.  (Stas, maybe you
> can suck this into the guide if you think it's something new...)
> 
> In doing some tweaking on one of our modperl servers earlier this
> week, I noticed via 'truss' that a bunch of 'stat's were being done
> for non-existent files.
> 
> The fact that they are non-existent is cool, because it's a site that
> has no document root, its sole purpose is to dynamically generate and
> cache date bar images in a bunch of different styles
> (http://date.boston.com/, BTW.)
> 
> But I didn't like the thought that these stat calls were happening for
> each request.
> 
> So, my solution was to add the following to the VirtualHost section
> for that host:
> 
> <VirtualHost 199.95.74.82:80>
>     .
>     .
>   PerlTransHandler      "sub { return OK; }"

one less subroutine call if you make that:

    PerlTransHandler Apache::OK

there should probably be an apache directive to turn off the default trans
handler, if you know you don't need it.  any any case, we should document
this somewhere, great find steve!


Re: Slight performance enhancement for dynamic sites.

Posted by Stas Bekman <sb...@iname.com>.
> > Here's a tiny performance tweak that I stumbled across that I don't
> > believe I've seen in any of the other online docs.  (Stas, maybe you
> > can suck this into the guide if you think it's something new...)
> > 
> > In doing some tweaking on one of our modperl servers earlier this
> > week, I noticed via 'truss' that a bunch of 'stat's were being done
> > for non-existent files.
> > 
> > The fact that they are non-existent is cool, because it's a site that
> > has no document root, its sole purpose is to dynamically generate and
> > cache date bar images in a bunch of different styles
> > (http://date.boston.com/, BTW.)
> > 
> > But I didn't like the thought that these stat calls were happening for
> > each request.
> > 
> > So, my solution was to add the following to the VirtualHost section
> > for that host:
> > 
> > <VirtualHost 199.95.74.82:80>
> >     .
> >     .
> >   PerlTransHandler      "sub { return OK; }"
> 
> one less subroutine call if you make that:
> 
>     PerlTransHandler Apache::OK
> 
> there should probably be an apache directive to turn off the default trans
> handler, if you know you don't need it.  any any case, we should document
> this somewhere, great find steve!

I think this should be investigated even futher because there are many
stat() calls for virtual paths!

I've started to document this in the guide using the Steve's contribution,
see what I've gotten:

=head1 Reducing the Number of stat() Calls

If you watch the server calls trace, while this processes a request,
you will notice a few stat() calls are made. For example when I
execute http://localhost/perl-status and I have my DocRoot set to
I</home/httpd/docs> I see:

  [snip]
  stat("/home/httpd/docs/perl-status", 0xbffff8cc) = -1 
                      ENOENT (No such file or directory)
  stat("/home/httpd/docs", {st_mode=S_IFDIR|0755, 
                                 st_size=1024, ...}) = 0
  [snip]

when running the server under C<strace> or C<truss> utility.

If you have some dynamically generated code (not from the script) and
your virtual relative URI is like I</news/perl/mod_perl/summary>
(there is no such a directory on the web server, the sub sections are
only used for requesting a specific report), this will generate
five(!) stat() calls, before the C<DocumentRoot> will be found. You
will see something like this:

  stat("/home/httpd/docs/news/perl/mod_perl/summary", 0xbffff744) = -1 
                      ENOENT (No such file or directory)
  stat("/home/httpd/docs/news/perl/mod_perl", 0xbffff744) = -1 
                      ENOENT (No such file or directory)
  stat("/home/httpd/docs/news/perl", 0xbffff744) = -1 
                      ENOENT (No such file or directory)
  stat("/home/httpd/docs/news", 0xbffff744) = -1 
                      ENOENT (No such file or directory)
  stat("/home/httpd/docs", {st_mode=S_IFDIR|0755, 
                                 st_size=1024, ...}) = 0


You should blame the installed by default C<TransHandler> for this
inefficiency. Of course you could supply your own one, which will be
smart enough not to look for this virtual path and immediately return
C<OK>. But in case that you have some virtual host that serves only
dynamically generated documents, you can override the default
C<PerlTransHandler> with this one:

  <VirtualHost 10.10.10.10:80>
    ...
    PerlTransHandler  Apache::OK
    ...
  </VirtualHost>

As you see it will affect only this specific virtual host.

This has the effect of short circuiting the normal C<TransHandler>
processing of trying to find a filesystem component that matches the
given URI -- no more 'stat's!

-------------------

P.S. watching your server under strace/truss can reveal more performance
hits than when trying to optimize the code itself!



_______________________________________________________________________
Stas Bekman    mailto:sbekman@iname.com      http://www.stason.org/stas
Perl,CGI,Apache,Linux,Web,Java,PC     http://www.stason.org/stas/TULARC
perl.apache.org    modperl.sourcegarden.org   perlmonth.com    perl.org
single o-> + single o-+ = singlesheaven    http://www.singlesheaven.com