Monthly Archives: March 2008

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!

Advertisements

3 Comments

Filed under Misc

Simone Cournoyer

SimoneSince a few days now, I have the pleasure to be the father of the most beautiful baby girl in the world. You might say that all parents think their child is the most beautiful, but that’s because you haven’t seen mine. I’m totally objective, ok?

I’ve already started to teach her some basic Ruby.

18 Comments

Filed under Misc