Saturday, July 30, 2011

Reducing Slug Size (Heroku)

If you check out http://devcenter.heroku.com/articles/slug-size, three tips are offered to reduce slug size:
  1. Move large assets like PDFs or audio files to asset storage
  2. Ignore files which are unnecessary to run the app. For example, unit tests, PSDs, or large design documents.
  3. When possible, reference a released gem by name in your Gemfile rather than loading it from source using the :git option.
Let's first look at #3.

I originally had the following in my Gemfile:
gem 'rails', :git => 'git://github.com/rails/rails.git', :branch => '3-1-stable'
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git'

When I changed this to
gem 'rails', '3.1.0.rc4' # :git => 'git://github.com/rails/rails.git' ...
gem 'sprockets', '2.0.0.beta.10' # :git => 'git://github.com/sstephenson/sprockets.git'
my slug size changed from 63 MB to 61 MB (specifically to 61.6 MB). But as Heroku recommends,
The maximum slug size is 100MB. Most apps should be far below this size. Anything under 10MB is good. If you exceed 40MB, you should think about trying to reduce the size of the slug.
...so I better keep going.

I moved on to #2. I created a .slugignore file with the following contents:
features
test
spec

In my case, just ignoring these folders in my app reduced my slug size from 61.6 MB to .... 61.6 MB. Negligible difference, unfortunately. I'm suspicious that adding the .slugignore didn't make a difference because when I set up this same app again at a different URL on heroku, the slug size was only 20.5 MB.

After filing a request to Heroku (https://support.heroku.com/requests/27593), I learned that, as the support staff member said, "There is currently a bug in bundler that is not cleaning old versions or unused gems out properly. We are working on upstreaming a fix for this, so hopefully sometime soon your slug size will lessen automatically with a push."

Guess it's back to waiting then. Nonetheless, I hope you found my little investigation above interesting if not helpful.

2 comments:

  1. I ran in the same issue and my slug is now exceeding 100MB which means no deploy anymore. Do you have found a solution?

    ReplyDelete
  2. First, try the 3 steps outlined above:
    1. Move large assets like PDFs or audio files to asset storage,
    2. Ignore files which are unnecessary to run the app. (I removed some test/ things, and that cleared up a lot of room)
    3. When possible, reference a released gem by name in your Gemfile rather than loading it from source using the :git option.

    Beyond that, though, there isn't much you can do other than upgrade your plan.
    If you have the issue with Bundler, then remember that the problem is not on your side; it's the bug on Bundler.

    Good luck :]

    ReplyDelete

Please be considerate in what you say.