Scaling a Rails app (Part 1 of 3) no comments

Posted by stephane Wed, 10 Oct 2007 18:32:53 GMT

One of the most interesting topic in the RailsConf was Scaling your Rails app. There are 2 ways of doing it:

  • adapt your code
  • adapt your servers

But the second one will not help to make your code faster. It will just help to give maximum resources to compute it right.

Summaries from the conference (sorry for the so few litterature it will be only a summarize):

Some theories

These theories are for big websites with millions of hits every month. This can involve thousand of servers, different location, ... BTW some tips can be use to help smaller configurations.

The 7 layers to be considered, a la OSI.

  • DNS
  • frontend
  • proxy
  • application server
  • application
  • backend (Db , filesystem)
  • OS

DNS

Nice website to check your DNS configuration: dnsstuff.com Good tool to optimize your DNS: speed, dispatching, and so on…: powerdns

DNS can be quite fast to address the right server from a request, scripts allow to manage complex configurations. The tip is to use 1 DNS entry per 1 controller, then managing part of the routing.

Frontend and Proxy

Load balancing is about dispatching requests taking in account the charge of each cluster.

Load balancers: Varnish HAProxy

Both look promising and HAProxy seems to be more and more popular.

Front end with load balancer: Nginx : fast, low memory usage, http server with load balancing, easy configuration, very good in front of mongrel cluster. Apache 2.2 + mod_proxy_balancer, you can find how to setup it in previous post: apapche, mongrel cluster, rails on a load balancer

Application server

  • mongrel server: enough for a personnal server gem install mongrel mongrel_rails start (more information)
  • mongrel_cluster: useful to scale up your configuration, need at least a multi-processor or multi server environnment. gem install mongrel_cluster mongrel_rails cluster::configure … mongrel_rails cluster::start
  • Evented Mongrel (swiftiply): it’s a mongrel based an event triggering
  • jruby / glassfish: the technology java comes with some good environment to speed up part of your application like connection to database (jdbc, pool connection)

to be continued (application, backend, OS, and some home benchmark)

Nginx and Mongrel cluster on debian 5 comments

Posted by stephane Sun, 23 Sep 2007 16:24:00 GMT

Nginx is a ‘small’ efficient http, load balancer server. More and more popular in Rails community, it’s a good front end for mongrel clusters. It’s seems to be a good replacement for apache, at least for the memory usage (on my test: 1 process use 1.3M against the more than 9M taken by 1 apache process). Benchmark on one single server are quite similar.

The process has been tested on debian 4.0r1 and should work on Ubuntu.

Installation

apt-get install nginx

or, if you want an up to date product:

1/ Prepare your system

apt-get install zlib1g-dev libgcrypt11-dev libpcre3-dev libssl-dev

2/ Download source

tar xzf nginx-0.6.12.tar.gz
cd nginx-0.6.12

3/ Compile it

./configure --pid-path=/usr/local/nginx/logs/nginx.pid \
    --sbin-path=/usr/local/sbin/nginx \
    --with-md5=/usr/lib \
    --with-sha1=/usr/lib \
    --with-http_ssl_module \
    --with-http_dav_module --prefix=/usr \
    --conf-path=/etc/nginx/nginx.conf \
    --pid-path=/var/run/nginx.pid \
    --lock-path=/var/run/nginx.lock \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log 

make

sudo make install

Configuration

The following configuration is for 1 nginx server with load balancing 3 mongrel in cluster:

1/ Mongrel cluster configuration

gem install mongrel_cluster -y

cd /var/www/my-app-path/current/

configures 3 mongrel in cluster, in production mode, starting at port 5000 and listening on localhost

sudo mongrel_rails cluster::configure -e production \
    -p 5000 -N 3 -c /var/www/my-app-path/current/ -a 127.0.0.1 \
    --user www-data

mongrel_rails cluster::start

2/ Nginx

nano /etc/nginx.conf

Use the nginx.conf file from brainspl.at website, change the 2 or 4 (if you use ssl) references to the path of your application (/var/www/my-app-path/current/)

/etc/init.d/nginx start

All these information come from many website (thanks to all), I put them together for my own usage, hope it’s helpfull.

Apache, Mongrel (cluster) and Rails are on a load balancer no comments

Posted by stephane Sat, 22 Sep 2007 19:04:00 GMT

Following the conference, and some information about scaling Rails application, I decided to investigate about it and write a post on it.

First, I tried to install FreeBSD as recommended for small configuration… Well, I still don’t get it, I’m not fan of this installation and stop trying to understand, instead I installed a Debian 4.0R1, not so bad and closer to what I know :)

Secondly, I want to try Nginx. First, need to find the good one to install on Debian, not last dev, maybe the one on the testing repository. Finally I found package with the 0.5.31, latest stable version. Easy to install with dpkg, I only wanted to simply configure static server and point on php application I have. Ouch, the php-cgi stuff is pretty much more complicated than expected, I had a look to a Rails configuration and gave up :p.(update: configuration of one server is not so complicated, at least for rails, not more than load_balancer in apache, but it is for php and if you want to dispatch URL on the same domain, it doenst seem trivial)

Then I went back to something I can handle: apache. I have read some article about 2.2 you can use with load_balancer and several mongrel instances. Let’s go for it. I found a very complete article: Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You used also by mongrel website about Apache Best Practice Deployment.

As I faced some issues, please be careful about the following:

1/ Mods to activate:

a2enmod proxy
a2enmod proxy_http
a2enmod rewrite
a2enmod deflate
a2enmod headers
a2enmod cache
a2enmod mem_cache
a2enmod file_cache 

2/ Forbidden access ? If you have some issue with forbidden access please check your proxy conf file and replace

Order deny,allow
Deny from all

by

Order allow,deny
Allow from all

Enjoy!

I’ll try again Nginx and maybe also pen / pound and litespeed. A buzzy load balancer: HAProxy. A lot of work is coming :p. If you have some feedback about these configuration don’t hesitate to share it :)

Ruby authentication system: Poll results no comments

Posted by stephane Wed, 19 Sep 2007 22:18:00 GMT

And the winner of 68 votes is ….

acts_as_authenticated with 47,06% of the votes

followed by

  • salt / sugar systems, 35,29%
  • other…, 13,24%
  • openid, 2,94%
  • auth_generator, 1,47%

Congratulations to the winner, it is a very nice and neat plugin. BTW at the RailsConf, we had a demonstration of an HTTP_AUTHENTICATION as a new feature of Rails 2.0. More’s coming…

Older posts: 1 2 3 4 5 6 ... 12