Wednesday, July 4, 2007

Using Gravatar plugin to embed avatars in rails views

Gravatar offers service to keep your globally recognizable avatars (gravatar). This tiny plugin offers rails view helper to embed gravatars in your views. It can also be used in blog, forums applications to insert gravatar to be visible instead of email. Here is how to install it:

$ ruby script/plugin install http://tools.assembla.com/svn/hasham/plugins/gravatar_tag


Here is sample usage in an erb template:

<%= gravatar_tag "user@domain.com", :size => "60x60"%>


The first parameter which is a email that user signed up with on gravatar.com is required. The other parameters are same as rails image_tag view helper.

Monday, July 2, 2007

SVN Cache made simple with Capistrano 2

You normally don't want to do complete checkout of your source control on every deployment with Capistrano. The SVN cache keeps copy of source code on server in separate directory on each deploy this copy of source code is updated and deployed to releases directory.

Implementing this kind of SVN cache is super simple in Capistrano 2, Just set deploy_via variable to remote_cache like this:

set :deploy_via, :remote_cache

Sunday, July 1, 2007

Mongrel is multi threaded, but rails is not thread safe

The main reason why we need to run multiple mongrel instances (pack of mongrels) for any high traffic website is that Ruby on Rails code is not thread safe. This is not the case with other Ruby frameworks like Camping, Merb and Og + Nitro. There is a synchronized block around the calls to Dispatcher.dispatch (in dispatch.rb) rest is multithreaded. so to get any sort of concurrency in serving request we need to run multiple mongrel instances.

In my experience 128 MB RAM is required to run single instance of mongrel server. which means you should not run more than 8 mongrels on your 1 GB RAM VPS. If the rails could be thread safe it would require lot less server resources to deploy rails with mongrels.