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!

3 Comments

Filed under Misc

3 responses to “How many applications can you fit in your VM ?

  1. 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. 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.

  3. 自己破産をすると原則としてすべての借金を支払う義務がなくなりますので(これを「免責」といいます),借金に追われることなく,収入を生活費に充てることができます。

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s