Because of not fully correct testing methodology, benchmark results are not fully correct. So, I decided to redo all tests. New benchmark results you can get in “Looking For Optimal Solution” series Summary post.

This week we have started one new project with Ruby on Rails as primary framework. My first task was to prepare runtime environment for it on one of our development servers. When I have tried to research how people doing it, I noted that there is no information about how to deploy rails application with nginx as frontend and what is performance of such solution. Before blindly make any decisions about future platform I’ve decided to make some performance tests of the some most popular rails web servers/frontends. Results of these tests you can find here with configuration samples for all software that I have used.

First of all I will describe hardware/software plaftorm of our development server. Our development server has following configuration:

CPU: 4 x XEON CPUs

Memory: 4 Gb of RAM

OS: Debian GNU/Linux Testing with recent 2.6 kernel

Later I will describe every used configuration and apache benchmarking tool results. At the end of article you will be see aggregated results and performance comparison diagram for all solutions. All tests was performed with following command:

$ ab -c 100 -n 10000 http://127.0.0.1:PORT/

where PORT is specific port number that has was chosen for every test.

So, first described solution will be simple WEBrick server (web server written entirely on ruby and included in rails framework). To start it I have used following command:

$ ./script/server --port 8080 -d

Results of this test was really impressive for me. I thought, that Webrick should be really slow, but it shown non-zero results ;-). So, here are results:

Web Server: WEBrick/1.3.1

Time taken for tests: 51.490

Time per request (mean): 514.896

Time per request (mean, across all concurrent requests): 5.149

Requests per second (mean): 194,21

Transfer rate (Kbytes/sec): 1478,88

As you can see, this results may be acceptable for some small projects or for development, but for big frequently visited site we need something faster.

Mongrel is a fast HTTP library and server for Ruby that is intended for hosting Ruby web applications of any kind using plain HTTP rather than FastCGI or SCGI. It is framework agnostic and already supports Ruby On Rails, Og+Nitro, and Camping frameworks.

The easiest way to get started with Mongrel is to install it via RubyGems and then run a Ruby on Rails application. You can do this easily:

And you’re all set. There’s quite a few options you can set for the start command. Use the mongrel_rails start -h to see them all.

My Mongrel test was performed for single mongrel process started with simple:

$ mongrel_rails start -d --port 8081

Results are following:

Web Server: Mongrel 0.3.13.3 (single process)

Time taken for tests: 17.212

Time per request (mean): 172.117

Time per request (mean, across all concurrent requests): 1.721

Requests per second (mean): 581,00

Transfer rate (Kbytes/sec): 4398,28

As you can see here, Mongrel is really faster comparing to simple WEBrick server, but let’s see what other servers can show.

Third test was done with simple tcp balancer (pen) and 5 processes of Mongrel. Pen has been installed from debian testing repository, so installation was simple (apt-get install pen). Testing was performed on pen process started with following command line:

In my test mongrel servers has been spawned by simple shell script written by me, but later I found mongrel-cluster – GemPlugin that wrappers the mongrel HTTP server and simplifies the deployment of webapps using a cluster of mongrel servers. So you can simply use it to make your setup process easier.

Results of this tests are better then in first test, but not as good as with single process:

Web Server: Mongrel 0.3.13.3 (5 processes through Pen balancer)

Time taken for tests: 19.864

Time per request (mean): 198.642

Time per request (mean, across all concurrent requests): 1.986

Requests per second (mean): 503,42

Transfer rate (Kbytes/sec): 3810,98

Next two test was performed in with two popular reverse-proxy servers: Nginx and Lighttpd and the same 5 Mongrel processes.

Because of some strange problems authors of mongrel server do not suggest using lighttpd for proxying, but as for my it works well.

And last test was performed with nginx reverse-proxy and web server. I decided to test it after all other solutions because there are no documents about its performance and I want to show, how to setup it and check its performance with Ruby on Rails when I know all other results… So, I have built it with standard commands: