InfoQ

News

High Performance Ruby MVC: Merb

Posted by Sebastien Auvray on Aug 26, 2007

Community
Ruby
Topics
Ruby on Rails ,
Performance & Scalability
Tags
Merb ,
Mongrel
There have been long debates on Rails performance. Rails can really slow down when your application deals with a lot of File exchange or concurrent connections. That is what Merb has been designed for. Ezra Zygmuntowicz, from Engine Yard, started working on Merb (Mongrel+Erb) 10 months ago and gave a presentation this month about it at Ruby Hoedown. Ezra originally tried to optimize Rails to make it more threadsafe, but at the end it was easier to make a new framework than trying to change ActionPack, (the View and Controller parts of Rails).

Merb is similar to Rails in many ways. What differentiates Merb from Rails is:
  • It has no cgi.rb
  • It has a clean room implementation of ActionPack
  • It is threadsafe with configurable Mutex Locks (Routing is also threadsafe)
  • It has been designed favoring simplicity and clarity over magic
  • A light core framework easy to extend through hacks
The key differences are:
  • No auto-render. The return value of your controller actions is what gets returned to client. You have to explicitly call a render method if you want it.
  • Merb's render method just returns a string, allowing for multiple renders and additional flexibility over similar functionality in Rails
  • PartControllers allow for encapsulated apps without big performance cost
A sample Merb application by Zack Chandler is available. Merb v0.4 Core is quite complete and Ezra promised it would stay light, with additional features provided by plugins.

What's in the pipeline for next releases ?
  • Docs, specs, tutorials
  • Rubinius compatibility
  • More profiling and optimizations
  • More tools and creature comforts
Concerning performance, Phil Misiowiec released an exhaustive comparison of Rails, Merb performance (using Swiftiply and Nginx). Phil's goal was to test real world clustering configurations. He looked at how concurrency affected the application running Rails vs Merb with various session management options (Disabled, Database stored, Memcached), and logging. In all tests, Merb performs better than Rails, and depending on the App Server and HTTP Server, it outperformed Rails by 5%-20%.

Phil draws the conclusion:
Using Evented Mongrels with Merb gives you the best bang for the buck overall when high concurrency is expected [...] be sure you understand your application's usage patterns and not over-engineer your solution. In most cases, running Rails with a standard Mongrel cluster may be just fine for you.
Speed? by Daniel Berger Posted Aug 28, 2007 6:32 AM
Bad link? by Kevin Williams Posted Aug 28, 2007 7:27 AM
Re: Bad link? by Sebastien Auvray Posted Aug 28, 2007 11:43 AM
Re: Speed? by Kirk Haines Posted Aug 29, 2007 6:43 PM
Not just speed...efficiency by Geoffrey Grosenbach Posted Aug 29, 2007 11:58 AM
Re: Not just speed...efficiency by Daniel Berger Posted Aug 31, 2007 2:17 PM
  1. Back to top

    Speed?

    Aug 28, 2007 6:32 AM by Daniel Berger

    I don't think a 5-20% speed increase is compelling, personally. Mind you, if Rails continues to get slower with each new release, it could become compelling. And, hey, competition is always good, so I'm glad I have a choice at least. :)

  2. Back to top

    Bad link?

    Aug 28, 2007 7:27 AM by Kevin Williams

    The Merb v0.4 link (merbivore.com/) gives me a 404 error.

  3. Back to top

    Re: Bad link?

    Aug 28, 2007 11:43 AM by Sebastien Auvray

    Hi Kevin,
    Indeed it seems to be down at the moment.
    You can still find a mirror at merb.rubyforge.org/files/README.html
    Regards,
    Sébastien.

  4. Back to top

    Not just speed...efficiency

    Aug 29, 2007 11:58 AM by Geoffrey Grosenbach

    It's about more than just speed. It's also about handling more traffic with fewer Mongrels and less memory. Merb lets Mongrel do more of the work and can spin off threads when needed to handle additional requests.

  5. Back to top

    Re: Speed?

    Aug 29, 2007 6:43 PM by Kirk Haines

    Just kind of throwing this out, but...

    The same benchmark, running through Swiftiply to 2 backend processes, on an AMD dual core Athlon 4200+ (so, a little bit faster than the test machine for Phil Misiowiec's benchmarks), with IOWA:

    Concurrency of 10: 1076/second
    Concurrency of 100: 995/second

  6. Back to top

    Re: Not just speed...efficiency

    Aug 31, 2007 2:17 PM by Daniel Berger

    Geoffrey, that's a good point. Are there any memory profiling statistics out there? I'd like to see that.

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.