Personal Bytes » Saving bandwith with mod_deflate!

Saving bandwith with mod_deflate!

Do you use Apache 2.x? On a machine powerful enough to have CPU idle time (or with the absence of real work)? Then mod_deflate is for you. HTTP 1.1 allows you to set an encoding request at the client whether he accepts compressed data or not. The web server will respond accordingly, and as you can state from here, it seems to be a very nice solution for quicker rending and for saving a lot of bandwith. Try I, I believe you won’t regret.

P.S. - I’ll try to do some benchmarks myself. I’m thinking about how to do them, being it on the server or on the time the request takes to get an answer to the client.

Update: I’m really looking forward to see a mod_gzip vs mod_deflate comparasion because if one takes more time compressing than sending the data then definitely it’s not worth it.


9 Responses to “Saving bandwith with mod_deflate!”

  1. mlopes
    Published at October 24th, 2005 at 1:52 pm

    Of course, this is not an excuse for using tables on your page layout. Using divs instead of tables with spacers will spare you another 60%. Check here how some managed to do that with Microsoft’s site (they’re always late).

  2. joel alexandre
    Published at October 24th, 2005 at 2:45 pm

    I put mod_deflate om my company’s site, but some clients using IE had problems viewing https pages. I couldn’t find out why. So i had to remove it from https pages.

    The problem with mod_deflate (or any other server side compression) is that after you click on the link, the browser gets a blank page until it renders the new page since it needs to get the full page before the rendering starts. That doesn’t happen when not using compression, since it starts to render “as soon” as it starts getting the page.

  3. mlopes
    Published at October 24th, 2005 at 3:57 pm

    The problem with mod_deflate (or any other server side compression) is that after you click on the link, the browser gets a blank page until it renders the new page since it needs to get the full page before the rendering starts. That doesn’t happen when not using compression, since it starts to render “as soon� as it starts getting the page.

    That raises an interesting question. Could there be any way to just return compressed data when required so? For example, most of the AJAX content being retrieved has to be read at once, so we could have a spot here to improve AJAX’s responseness.

  4. joel alexandre
    Published at October 24th, 2005 at 4:26 pm

    i personally use compression with php. This way i only compress what i want. I prefer to use http://pt.php.net/ob_gzhandler than apache because it’s easier control. And since the server has no static pages, that is no problem.

  5. Gonçalo Silva
    Published at October 24th, 2005 at 6:43 pm

    If you want to compress php pages, maybe you shoud put “zlib.output_compression = on” in your php.ini instead of using a the ob_gzhandler function, this way all process is transparent.

  6. mlopes
    Published at October 24th, 2005 at 7:41 pm

    Gonçalo, is there any way to select the compression level using that method? The ob_gzhandler allows it. And does that method also interfere with IE? Unfortunately there is a significant ammount of people still using that thing they call “browser”.

  7. Joel Alexandre
    Published at October 24th, 2005 at 7:46 pm

    to use a transparent process then apache mod_deflate is more transparent (it works with non php pages).
    With php’s ob_gzhandler you can control which pages should be compressed or not. (ex: downloads forced by php cannot be compressed or IE will go nuts). That is why i use it on my pages.

  8. Gonçalo Silva
    Published at October 24th, 2005 at 8:34 pm

    mlopes: yes, there is the “zlib.output_compression_level=integer” to control that. I never had any probs using gzip this way with any kind of browsers, but there is allways that danger when we speak about IE ;)

    Joel: mod_deflate isn’t a option yet, i’m still using apaches 1.3. I remove mod_gzip from my apaches when php started supporting the zlib.output_compression because almost all my server’s pages are in php and i read some article saying that mod_gzip consume more system resources that PHP native gzip.

    Even so i can still compress some non php pages by moving it extension, example:

    [gngs@neon public_html]$ cp index.html index.php

    ngs@neon public_html]$ lynx http://paradigma.pt/~gngs/index.html –head –dump
    HTTP/1.1 200 OK
    Date: Mon, 24 Oct 2005 19:25:53 GMT
    Server: Apache
    Last-Modified: Mon, 24 Oct 2005 19:24:13 GMT
    ETag: “c34c3-4b4-435d34dd”
    Accept-Ranges: bytes
    Content-Length: 1204
    Connection: close
    Content-Type: text/html

    ———
    [gngs@neon public_html]$ lynx http://paradigma.pt/~gngs/index.php –head

    HTTP/1.1 200 OK
    Date: Mon, 24 Oct 2005 19:28:57 GMT
    Server: Apache
    X-Powered-By: PHP/4.4.0
    Content-Encoding: gzip
    Vary: Accept-Encoding
    Connection: close
    Content-Type: text/html

  9. Joel Alexandre
    Published at October 24th, 2005 at 11:09 pm

    mlopes: you said that the compression level afects how IE opens compressed pages. If so, what should be the better level for IE. And where can i get some info on that?

    thanks
    mail: joel.alexandrezmail.pt