Hi, after looking at mod_gzip, Apache::Gzip, Apache::GzipChain
and so on, I decided to try Apache::Compress, with some doubt that
it was "worth it"

There were a few hiccups, but it worked out great.

To test "in production" I created an alias /x to my cgi location,
and then added

Aloas /y /path/to/my/modperl/programs/
Aloas /x /path/to/my/modperl/programs/
PerlModule Apache::Filter
PerlModule Apache::RegistryNG
PerlModule Apache::RegistryBB

# original gateway
<Location /y>
  ..
  SetHandler perl-script
  PerlHandler Apache::RegistryBB->handler
  ..
</Location>

# optional compressing gateway
<Location /x>
  ..
  SetHandler perl-script
  PerlSetVar Filter on
  PerlHandler Apache::RegistryFilter Apache::Compress
  ..
</Location>

I also changed Apache::RegistryFilter to subclass from Apache::RegistryBB
(bare bones), as that is my preferred harness.. (if you mix 
Registry classes, mod_perl will not recognize the same script as
the same script and recompile it again, wasting memory).

Ok so I found one problem ..

If a client is 1.1 but does not accept gzip, then I'd get an internal
server error and a perl complaint about an invalid file handle GENNNN.
I fixed this by changing the fallback (non compressing filter) code in
Apache::Compress to print, rather than use send_fd() .. I don't know why
this worked, but it does..

Next problem .. the zoo of browsers out there that lie about being
able to handle gzip.. I don't want to assume they all work, then have
users look at pages of gibberish, so I used mod_rewrite to conditionally
use the compressing gateway initially ONLY for two browser regexps:
(but they are by far the most popular):

RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[45].*Windows.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[45].*Opera.*
RewriteRule ^(.*) http://back.end.server.ip/x/mysite$1 [P]

One could also, I guess, offer a new subdomain using mod_rewrite..
 www.mysite.com (directed to non compressing URL)
 fast.mysite.com (directed to compressing URL)

Next problem .. I had an unfortunate habit of printing
Location: blah\n\n
from my mod_perl programs which breaks under the compressing filter
chain so rather than fix this now, I used mod_rewrite RewriteRule
again to strip out my URLs that have this kind of redirect, to
point to the /y (non compressing) handler regardless.

Result: this is the good part :-)

* Since all my content is dynamic and most is HTML with fiddly stuff,
  nett site outgoing bandwidth (and bill) has dropped by 2/3rds !!

* the modperl machine is now working harder.. where previously it was
  delivering approx 300k/sec and was 20% cpu busy, it is now delivering
  the same page count but 142kb/sec of compressed data but is 40% cpu
  busy .. since it is SMP I'm guessing it takes 40% of one PIII 1ghz
  to handle the load of about 140k/sec of compressed html..

* page sizes are MUCH smaller, in many/most cases...
  home page --> 50k --> 12k
  one 50 post forum thread --> 120k --> 22k
  large html table with finnicky cell colors etc --> 87k --> 8k

* load times from the users perspective, even on a DSL line, feel
  twice as fast. On a modem, for some examples above, it would feel
  5x faster! my subjective feel under MSIE on just a 300mhz laptop,
  but connected to a 784kbps DSL line, was that pages appear
  twice as fast.. 

* my bandwidth bill drops by 2/3rd (would be much more but html was
  not 100% of bandwidth, plus I'm conservative about switching it
  on for more browsers)..

AWESOME..

-Justin

Reply via email to