Is compressing the output of your webserver cost effective?

29 Aug 2008

For a minute, forget how to compress output from your webserver, and if it's a good idea in general, and instead is it cost effective?

Ok, for you executive types the answer is yes, and very much so.

For the rest of us: with compression you are using less bandwidth, but compressing content also takes CPUs. If you have your own setup in a datacenter, this is really painful to estimate since you buy bandwidth in huge increments. In other words, there is no reason to save bandwidth until you hit your limits, and then it's really important. Likewise with CPU costs: you have mixed-use machines all using the same datacenter, using the same power all of which is priced in large increments.

Fortunately, someone else already figured this stuff out: Amazon with it's EC2. On the low end it's:

  • $0.10 per CPU hour
  • $0.17 per gigabyte data out.

Let's also assume:

  • gzip will provide 2x compression
  • gzip can compress 1G in 3minutes (5% of one hour)

So if you pump out 2G of data without compression, the serving cost is 2 × $0.17 = $0.34, plus incidental cpu cost of course

With compression, the cost is 0.5 × 2 × $0.17 + (3 / 60) × $0.10 = $0.171.

Doing a bit more thinking, for compression to not be cost effective, the compression ratio has to be very low, or be very slow, no matter what the bandwidth cost is.

In other words, compress away!

Now how is a different question. Since it's the wonderful world of web development almost nothing works correctly and has lots of special cases. But that's another article.