A Simple and a Fast App: Sinatra, Espresso, Padrino, Goliath, and Ruby on Rails

by Eugene MelnikovJune 12, 2013
This blog post shares the results of comparing five popular Ruby frameworks across the amount of requests made per second.

There is a number of Ruby frameworks that allow for creating amazing feature-rich applications. However, very often you need some simple functionality, and your main goal is to ensure the fastest performance possible. I decided to compare performance of the basic applications that were created with Sinatra, Espresso, Padrino, Goliath, and Ruby on Rails to find out which framework is the fastest one.

For the comparison, I used ApacheBench 2.3 ab -n 1000 -c 100 localhost, CPU 2.53 GHz Intel Core 2 Duo, RAM 8 GB 1333 MHz DDR3, OS X 10.8.4, ruby 2.0.0p0, MySQL 5.6.10 in the development environment. The only parameter in all the tables is the amount of requests per second (r/s).

 

Sinatra 1.4.3

Interesting facts. When I used stubbed “Hello World!” in index.haml, I got performance decrease for 5 r/s. WEBrick produced an interesting result when I used views and database. It was faster with MySQL then without for 8 r/s. I also got performance decrease when I wrapped the application in class App < Sinatra::Application and added config.ru with run App.new for Unicorn.

Web ServerNo views and DBViews (slim)Views (slim) + MySQL (sequel)
WEBrick 1.3.1330119126
Thin 1.5.1980146133
Unicorn 4.6.264512295

After adding config.ru, Thin started to work slower on 200r/s. It’s not just an inaccuracy, because I have checked all the controversial results multiple times and got pretty stable speeds. So, you should be extremely careful when you write a high-load application, because any small change can slow down it and run benchmark tests on the web server that you are going to use in production.

Since Thin showed the best results, all my next tests I’ll do with only this web server and try to keep my application as simple as possible.

 

Espresso 0.4.8

Now you can see that Espresso is incredibly faster than Sinatra, and we also got one more proof that just using views can significantly change your application speed to worth.

No views and DBViews (slim)MySQL (sequel)Views (slim) + MySQL (sequel)
2626201615171172

However, in case of Espresso, database usage decreased performance more than views. Always remember about caching popular data in memory.

 

Padrino 0.11.2

Despite Padrino is built on Sinatra and provides a lot of helpful stuff similar to Rails, performance is still close to a clean Sinatra application. This fact cannot be but a source of joy.

CacheNo views and DBViews (slim)MySQL (sequel)Views (slim) + MySQL (sequel)
No cache82511354592
Memory1050207745112

Before I ran all the tests using global layout plus layout for action. However, for the last test, I made an exception and checked without global layout. I got 167 r/s instead of 92 r/s. It’s even more than the result without database. The same result I got with caching, but, in this case, it was less than the result without database. So, when you make a high-load application and have to use views, try to avoid using global layouts if it’s possible.

 

Goliath 1.0.2

Goliath results looks a bit strange for me, because I thought that this framework is the fastest thanks to the HTTP server of its own.

No views and DBViews (slim)MySQL (sequel)Views (slim) + MySQL (sequel)
39910926184

Please don’t hesitate to blame my results and propose your version of benchmark testing.

 

Rails 4.0.0.rc1

I enabled caching classes in development.rb, as well as disabled sessions and protection from forgery for these tests.

No views and DBViews (slim)MySQL (sequel)Views (slim) + MySQL (sequel)
461398316292

I used Sequel instead of ActiveRecord to make results more fair. You can see that results are close to Goliath’s, but little bit better.

You can make sure all applications I made were really similar, and tests are not taken from ceil. Hope it helped you to choose the right framework.

You can also check out the updated version of this comparison.

 

Further reading