boldr by Nicolas Mérouze

The current state of Ruby concurrency

I'm working on a project with Websockets and it's a been hard to do it in Ruby compared to Node.js and Clojure. At the start everything worked great but if you need something particular you're stuck. I rewrote it in Node.js in a few hours.

Concurrency was a myth in Ruby some years ago but progress has been made and has been demystified and discussed. It is now more mature and understandable but needs some more love.

Concurrency doesn't need callbacks

Event-based libraries are the hot thing right now because Node.js made it popular. In Ruby we have EventMachine but it's a bit complicated and frankly callbacks are a mess. We have EM::Synchrony too to do EventMachine without callbacks (and with fibers) and Goliath to create Web backends with EM::Synchrony.

The missing libraries

Goliath is pretty cool, there are a lot of examples to get you started but the documentation is a bit thin and it requires wrappers around existing libraries so you can't use whatever you want. I've tried to write something with Goliath and it was very difficult to find what I could use and what I couldn't. In addition the wrappers can have different APIs than the original libraries which do not help you to get it working (sometimes it's because the wrappers are not updated very often).

Cramp is a framework like Goliath but has the same pitfalls.

Celluloid can be the solution

The promise of Celluloid is "Painless multithreaded programming for Ruby" which can get our hopes high. And there's an evented library based on Celluloid called Celluloid::IO which gives us more hope "Evented I/O for Celluloid actors. Build fast evented programs like you would with EventMachine or Node.js using regular synchronous Ruby libraries based on TCPSocket". It seems very great and there's a good documentation on the wiki but unfortunately few examples.

We need to push concurrency forward

The reason Node.js had a steady growth is that it's simple to get started. You don't need to wonder what are the compatible libraries, there was documentation from the start and you didn't need to learn another programming language (like you would do with Erlang, Haskell or Clojure) because you usually write Javascript even if it's a little bit.

I have the impression that it's rocket science to do concurrency in Ruby but so simple elsewhere, simply because there is a lack of clear documentation (and compatible libraries if you don't use Celluloid). If you want the community to adopt your solution you have to market your stuff, not just with logos and good headlines but with documentation and examples too (I pointing my finger at Celluloid here). Rails is the perfect example of good marketing, it has a shiny presentation but the main thing was the video to build your blog in 10 minutes. Create a wonderful real-world example and show how simple your solution is and people will use it.

If you liked the article and/or want to talk to me about it, you can follow me on twitter.