Gzip and Slimmer optimization anecdote


30th of January 2007

I've wanted to Gzip the static content (CSS & Javascript) on my sites for a long time but never found a good enough solution. mod_gzip is out of the question because as far as I've understood it it does a compression on the fly, every time you request the file.

Other solutions have disappointed me because enabling gzip compression has been for all content. I don't want my HTML files gzipped because they're rendered on the fly based on business logic plus by compressing the HTML files. Long story short my yet-to-be-released app now serves the following files from Zope but are only compressed and whitespace slimmed once per server restart:

 FILE               ORIG SIZE  NEW SIZE   REDUCTION
 screen.css             15224      2738   556%
 print.css               2633       885   298%
 jquery-latest.js*      57712     18130   318%
 jquery-latest.pack.js  20461     10513   195%
 common.js               3803      1131   336%
 complete-expense.js    18184      2847   639%
 Total                 118017     36244   326%

 * only used in debug mode

Yes that's right. The static files are now 326% smaller in file size and since the complexity is O(1) the CPU overhead is virtually none. What's cool about this is as an application developer I don't have to worry about it once the files have been set on the class. I never actually see the slimmed or compressed files. The code is also clever enough to serve the uncompressed version of the file if the server doesn't accept gzip using HTTP_ACCEPT_ENCODING.

To make things even more optimized; add the fact that I'm running this Zope behind Squid and with this command:

 # nice -n 20 ab2 -n1000 -c10 http://XXX/misc_/MExpenses/screen.css

I get this lovely result:

 Concurrency Level:      10
 Time taken for tests:   0.372630 seconds
 Complete requests:      1000
 Failed requests:        0
 Write errors:           0
 Total transferred:      3168000 bytes
 HTML transferred:       2738000 bytes
 Requests per second:    2683.63 [#/sec] (mean)
 Time per request:       3.726 [ms] (mean)
 Time per request:       0.373 [ms] (mean, across all concurrent requests)
 Transfer rate:          8300.46 [Kbytes/sec] received

Bare in mind that this is also proxied by Apache2 to get the extra comfort that Apache2 gives us.

Doing the same benchmark on the screen.css file WITH Squid but without gzipping and slimming it I get this result:

 Concurrency Level:      10
 Time taken for tests:   1.471274 seconds
 Complete requests:      1000
 Failed requests:        0
 Write errors:           0
 Total transferred:      15613552 bytes
 HTML transferred:       15224000 bytes
 Requests per second:    679.68 [#/sec] (mean)
 Time per request:       14.713 [ms] (mean)
 Time per request:       1.471 [ms] (mean, across all concurrent requests)
 Transfer rate:          10363.13 [Kbytes/sec] received

(Without Squid caching, my Zope in this instance does 242.4 [#/sec] for the same file)

Apart from making Zope does less hard work for stupid static files, I've managed to go from 242 requests per second up to 2684 requests per second. Not bad :)



Comment

Show all 7 comments
 
Name:
Email:
hide my email address.

Your email address will be encoded to prevent email-extraction spiders from reading it so you won't get spammed if you decide to show your email address.