blog Code giants heroku rails

Reducing Heroku Cost with Asset Pipeline Sync

GiantsLive which is hosted on the new heroku Rails 3/Cedar platform a single ‘dyno’. If you don’t know what heroku is, essentially it’s a cloud web hosting platform, and one of it’s finest features is that your first 750 ‘computation hours’ in a month are absolutely free. Properly free, like a lunch at that church on Stranmillis Road on a Thursday.

Over the last few months the site’s traffic has gotten a little heavier than before and occasionally under pressure on big weekends like when Nottingham Panthers or Sheffield Steelers (the ice hockey rivals with the biggest active fan bases in the UK) play. The site struggled, partly because every page is access controlled and therefore can’t make maximum use of caching. I’m not going to discuss customer/pay-per-view quantities but in terms of expenditure, the system began to run up extra fees on the platform as it was consuming between $10 and $40 per month (magically, about 300-1200 extra hours per month).

The site doesn’t host or provide the video service, it’s a third party platform and so there’s no way this amount of processing is taking place. The problem? Every html request was pulling in css files, javascript, flash elements (on the streaming page) and images. Each one, however minified, was taking a http request and consuming dyno time.

Trust Dave Rice to have the answer… Asset Sync (code on github) is Rumble Labs’ addition to Rails 3’s Asset Pipeline. In very rough terms, Asset Pipeline version controls site assets and removes static references to the public folder. Asset Sync takes all of your compiled assets, and pushes them into an Amazon S3 bucket (wherever in the world you choose). They are then served totally independently of your site’s infrastructure, taking the load off your processing system meaning you can service more application requests per second.

This months’ heroku bill just came in, at $2 for all currently running apps, and after checking amazon billing the GiantsLive statement came to 10.475 gigabytes transferred in 39,788 requests, at a grand total… of $1.39+vat.

So if you use heroku, and your app is in production, put your assets on S3 and use asset_sync, you will save money. Thanks Rumblers!