Thursday, July 5, 2012

integrate http reverse proxy cache server with Rails and Varnish



  • Setup Apache and make a virtual host to listen it on other port like 8080
  • Install varnish and listens it on port 80
  • For the Varnish, you need to do configuration on two files like bellow





Here is the requesting flow: Browser ---> Varnish---->Apache2----->Application Server
That means, when u request through browser, it request to Varnish(on port 80) and if varnish has cached then it served directly to client(browser) without interfering apache otherwise Varnish passes the request to apache...In this way you can scale your Rails app heavily and serve a lot of requests concurrently with low memory and low resource consumed.

Some varnish useful commands:
  • Restart Varnish - /etc/init.d/varnish restart
  • Show Varnish statistics - varnishstat
  • Test to see response is coming through Varnish -
    curl -I http://www.your_app_url.com



Friday, February 10, 2012

Parallel Processing in Ruby On Rails

I used ruby's fork when I was sending 60,000 emails from one of Rails applications and it is wise to split the big result set and send emails of each chunk parallely on forks for faster processing! Here is a sample ruby code for processing N length data.

I tested it on Ubuntu 11, ruby 1.9.2, Rails 3.0.10