---
title: Parallel Gem Installing Using Bundler
teaser:
tags: web,ruby
author: Prem Sichanugrist
published_on: 2013-08-28
---

Do you realize how much time you've spent running `bundle install`?

![sword fighting][swordfight_pic]]

No more sword fighting! [Bundler][bundler] 1.4.0 [adds support for parallel
installation][PR]. You can pass in `--jobs SIZE` as a parameter to `bundle
config`<sup id="fnref-2013-08-27-1">[1](#fn-2013-08-27-1)</sup>. I recommend
setting the size to one less the number of CPU cores on your machine<sup
id="fnref-2013-08-27-2">[2](#fn-2013-08-27-2)</sup>.

## But Prem, how much time could I save

Let's benchmark this! I'm going to run `bundle install` on a freshly-created
Rails app.

Before:

    $ rvm gemset use j1 --create
    Using ruby-2.0.0-p247 with gemset j1
    $ time bundle install
    # ... snip ...
    bundle install  5.75s user 1.76s system 24% cpu 30.679 total

After:

    $ rvm gemset use j8 --create
    Using ruby-2.0.0-p247 with gemset j8
    $ bundle config --global --jobs 8
    $ time bundle install
    # ... snip ...
    bundle install  7.48s user 2.59s system 86% cpu 11.681 total

That's about 19 seconds faster (~61.90% improvement) over regular `bundle install`!!!

## That's awesome! How can I use this now

Simple! Just install a prerelease version of Bundler, and you should be good to go:

`gem install bundler --pre`

Then, configure Bundler to parallelize on your machine globally:

    bundle config --global jobs 7

If you're not sure how many cores you have, you can find out dynamically.
Here's how we set up that configuration automatically on OS X in our [laptop
script][laptop]:

    number_of_cores=`sysctl -n hw.ncpu`
    bundle config --global jobs `expr $number_of_cores - 1`

[laptop]: https://github.com/thoughtbot/laptop/pull/166

If you want to edit or delete the configuration directly, it can be located here:

    vim ~/.bundle/config

And now, you can spend less time on sword fighting<sup
id="fnref-2013-08-27-3">[3](#fn-2013-08-27-3)</sup>, and more time on writing
actual code.

## Credit

I would like to give my thanks to [Kohei Suzuki][eagletmt] who submitted this
patch to Bundler and [Murahashi Kenichi][sanemat] for bringing this into my
attention on [Appraisal][appraisal_PR].

---

1. Sadly, this option will not be a default, since it [does not work every
   time](https://github.com/bundler/bundler/commit/7c6c3af2) and you might want
   to fall back to do sequential installation in that case.
   [↩](#fnref-2013-08-27-1)
1. I originally recommended you to set the size to be equal to the number of
   your CPU cores. However, it turned out that [setting the number to be
   N-1](http://archlever.blogspot.com/2013/09/lies-damned-lies-and-truths-backed-by.html)
   will yield a better result.[↩](#fnref-2013-08-27-2)
1. Well, that could also be considered as a downside as well.
   [↩](#fnref-2013-08-27-3)

[swordfight_pic]: http://media.tumblr.com/76501d7e366e32c68e05bf0e931206ac/tumblr_inline_ms7d9qF6Hb1qz4rgp.png
[bundler]: http://bundler.io/
[PR]: https://github.com/bundler/bundler/pull/2481
[appraisal_PR]: https://github.com/thoughtbot/appraisal/pull/61
[eagletmt]: https://twitter.com/eagletmt
[sanemat]: https://twitter.com/sanemat
