The great Node.js versus Ruby on Rails speed test

There is a server environment for web development I have heard mentioned a lot  called Ruby on Rails. Though I am just starting to learn JavaScript, I thought I would check it out because I have heard so much about it and one of my friends recommended it to me. I am sure for most programmers Ruby on Rails is already yesterday’s news, but it is new to me, so I thought I would give it a try. I would really like to learn just one language at a time when I am starting out, but Ruby on Rails sounded interesting, and maybe if it’s good I can try to write the web client in Ruby on Rails somehow too.

The first obstacle I ran into was how to get it installed. I am running on Windows so my options are limited. The very first option on the Ruby on Rails web site is to compile from source code! Are they actually trying to be hostile to beginners?

They had the option to download binaries for Windows, which took me to this page which is a big jumbled up list of Ruby versions and files (do I want 1.8.7 or 1.9.3?), trying to figure out how to get Ruby gems to work, and not having a whole lot of luck, I finally found Rails Installer which did everything for me and was pretty nice overall. It was still much easier to get Node.js installed, and I’m really confused to why the rubyonrails.org web site links to the site with a big list of files instead of Rails Installer.

The main thing I was worried about was speed. I had heard Ruby is something like the slowest language on the planet, so if my game server is going to need one server for 50 people with Node.js, how many is it going to need for Ruby on Rails?

I had the Node.js hello world example loaded, and opened up the Chrome Network tab so I could measure the speed of Node.js as compared to Rails. I loaded the page with the network tab open and checked the time: 2ms. Pretty fast! (I think!)

The next thing to do was to get a hello world working in Ruby on Rails, since unlike the Node.js web site they do not post a Ruby on Rails hello world example code on rubyonrails.org for some reason. I tried to google around for how to get Hello World going, and found this link to the Ruby on Rails wiki that was down (and I’m beginning to think Ruby on Rails is a bad choice) and when I finally got it to work, the whole Wiki was empty and full of spam. Ruby on Rails documentation seems to be pretty bad, which kind of surprises me because it’s so old, you think they would have good documentation by now, and it makes your web framework look pretty bad when your own wiki won’t load and is full of spam.

Eventually I found this blog post that had nice step-by-step instructions, and I finally had my hello world example up and running and even loaded in my browser.

Well, it was time for the moment of truth. How fast is Ruby on Rails compared to Node.js? It took 309ms! In case you can’t do math that’s like 150x slower than Node.js. I figured this was just a fluke and maybe if I refresh it will be faster, and it was, but it was still 20ms, which is 10x slower than Node.js. So Ruby on Rails not only starts up really slow, even after it gets running it’s still very, very slow, and this is just doing Hello World. If my Node.js server can handle 50 users, does that mean a Ruby on Rails server will only be able to handle 5?

The more I googled around the more I saw a pattern between the Ruby on Rails and the Node.js programmers: Ruby on Rails programmers don’t care about speed, and Node.js programmers do! When I would google for speed and Ruby on Rails I saw lots of people dismissing speed and talking about how it’s not important. Node.js is not like that and really seems to value performance. Since I’m writing a game and I want it to be fast Ruby on Rails was probably a bad choice.

I did some further reading on Node.js versus Ruby on Rails and found this blog post which confirmed my suspicions. This post was written by a Ruby on Rails expert who decided to switch to Node.js, so I knew he wasn’t just saying that stuff because he likes Node.js, he has hands on Ruby on Rails experience.

Ruby on Rails was created in the days before HTML5 so it has a lot of legacy around the old way of making web applications, which isn’t with a JavaScript frontend, but with HTML pages assembled by the server. Node.js is a much newer technology and so it doesn’t have this legacy, and is instead built on modern standards. Also Node.js has event-driven non-blocking I/O which is probably the main reason it’s faster than Ruby on Rails.

Then I found the real clincher: Ruby on Rails doesn’t support Socket.io! They want me to use AJAX instead, which is old and slow, and there’s no way I’m going to use it to write a game.

And so ends my brief investigation of Ruby on Rails versus Node.js. I am fully confident going forward that Node.js is the right choice for the backend of my game, and best of all I don’t have to learn two languages when I could just use one. I am very excited to try out the Chilly Framework for building HTML5 games as it sounds like exactly what I need.

Long story short, if you are trying to build an HTML5/JS game, don’t even bother looking at Ruby on Rails, because it’s too old and two slow and makes you learnt at least two languages on top of everything else.

1 thought on “The great Node.js versus Ruby on Rails speed test

  1. I work in a consultancy that predominantly uses popular tech like Django, Rails, and Node. And this post makes no sense.

    Node is an async library. Rails is an application framework. You’re conflating a chainsaw with a lawnmower just because they both cut things.

    The first problem is your search for a “hello world” Rails app. Rails employs an MVC pattern for separating application logic. What would a “hello world” app in Rails even entail? You could make a Message model, seed the database with “hello world” messages, pluck one from the database, route it through the controller and render it in the view. Or you can render it straight from the view as a .html file that doesn’t even hit the Rails stack. Or you can “hello world” straight from Rails’ Rack middleware. Either of the latter two would be as fast as your Node “hello world” loop since it’s nothing but a local emitter.

    The second problem is that you are benchmarking Rails in development mode. Among other things, the environment is reloaded on refresh so you don’t have to restart the dev server on file changes.

    The third problem reveals the crux of your conflation with statements like “Node is faster than Rails because it’s evented with async libraries”. Huh? That’s like saying that driving is faster than going to work because you’re riding in a car. In other words, using Rails doesn’t preclude you from using async libraries like EventMachine that considerably predate Node for when you need async events.

    We use async/concurrent process like Faye (Ruby), Node (Javascript), Twister2 (Python), and Goliath (Ruby) at work alongside Django and Rails apps. Django/Rails run the application and we spin up async processes/servers to do things like manage sockets, emit pubsub events, or give our application real-time functionality.

    It’s been 15 days since you wrote this, so you’ve probably continued to explore Node and seen that it’s not an application framework. Node is great when you need async libraries. Django and Rails are great for when you want to structure an entire application domain or even just to provide API endpoints for your Node application or Backbone.js. I hope I helped deconflate the two.

Leave a comment