How many applications can you fit in your VM ?

SanboxSo there I was last night, unable to sleep after Simone finally did went to sleep. I started to play with Why’s Freaky Freaky Sandbox. I knew some people thought about using this to run multiple Rails applications inside the same VM but nobody actually did.

Installing the Sandbox

Installing the Sandbox is kinda scary cause you have to patch Ruby and install it using setup.rb which is not the typical gem install.

Patch Ruby 1.8.6:

cd /path/to/src/ruby-1.8.6
wget http://code.whytheluckystiff.net/svn/sandbox/trunk/patch/ruby-1.8.6-sandbox_needs.patch
patch -p1 < ruby-1.8.6-sandbox_needs.patch
make
sudo make install

Install the Extension:

svn co http://code.whytheluckystiff.net/svn/sandbox/trunk sandbox
cd sandbox
sudo ruby setup.rb

See InstallingTheSandbox for the official guide.

What the Sandbox allows?

It clones the Ruby environment and keeps all the objects seperated in their own freaky freaky sandbox! It’s a bit like running a VM inside another VM!

Rails + Multiple VMs, yeaaaah baby you guessed it!

Rack Sandbox

So I’m hacking on this thing: http://github.com/macournoyer/rack_sandbox that runs a Rack application inside a Sandbox. I was able to run 2 very-very bare bone Rails applications (no db, no session, no plugins) inside the same VM, all served by one single Thin instance!


map http://myfirstapp.com do
  run Rack::Adapter::SandboxedRails.new(:root => /path/to/a/rails_app)
end
map http://mysecondapp.com do
  run Rack::Adapter::SandboxedRails.new(:root => /path/to/another/rails_app)
end

I don’t fully understand how the Sandbox works, I had to do some crazy hacking to make it work and haven’t tested it with several Rails applications. A lot more work needs to be done before this is even usable.

But this allows to save all the memory overhead of running a separate ruby process which is about 60 MB on my machine. So instead of costing you 120 MB to run 2 simple Rails app it’s only around 63 MB.

git clone git://github.com/macournoyer/rack_sandbox.git

Feel free to clone, pull and fork!

2 Responses to “How many applications can you fit in your VM ?”


  1. 1 oldmoe March 25, 2008 at 4:02 pm

    Any progress here? and do you think it makes sense to get the sandboxes to share more code (given that it is re-entrant of course). The biggest draw back to Rails deployments is the memory requirement.

    Our servers are maxed on memory usage even though they have much more processing power to go.

  2. 2 macournoyer March 27, 2008 at 2:24 pm

    hey oldmoe,

    I haven’t workon this since but the saving on memory is sure significant. Like I mention in the post, 60 MB for the Ruby process + 3 MB per Rails app on my machine. 3 MB per app is very low.

    But the problem is that, it’s a big hack, I don’t know how stable this can get.

Leave a Reply




RefactorMyCode.comrefactorer Recommend Me
Top Blogues page counter Add to Technorati Favorites

Blog Stats

  • 83,520 hits