Reality Check

Filed under: rails mongrel 

A request that pops up on the Nginx mailing list every so often is the ability for Nginx to restrict backend servers in a clustered proxy to each receiving only one request at a time. This request invariably comes from someone using Rails who has discovered that Rails isn't thread-safe and can therefore only handle one request at a time.

For some reason I was under the impression that Mongrel was intended to help solve (or at least work around) this issue, so I decided to get a bit more info from the Mongrel site.

It was there that I found this gem:

Rails is not thread safe so if you have long running actions then you can potentially block the server. Keep in mind that this is the case for any server, it’s just more pronounced for Rails.

Okay, seriously. There is so much wrong with this statement that the question isn't whether or not to laugh at it, but whether or not to find the author's phone number, call him up, and laugh in his face.

First off, while I'm less than certain the author intended to say this, the awkward structure of the paragraph could lead some to believe that no servers are thread-safe. Fact is, with the exception of potential programming errors, all servers are thread-safe (either fully reentrant or protected with locks to force serialization at critical points). Rails and perhaps a few homework assignments from mediocre junior college students being the exceptions.

While I doubt the author truly meant to assert the above, I am certain he meant to convey the fact that all servers are potentially susceptible to dropping requests when there aren't enough resources to handle them all. Obviously this assertion is true at some level. Where the falsehood lies is where the resource constraint comes from. With Rails, there is a single shared resource that is constantly exhausted whenever there's a request: it's Rails itself. With other servers, you'd have to exhaust system resources such as RAM, threads, TCP sockets, CPU time, etc. Other servers don't have bottlenecks designed into them. Claiming all servers have this problem is akin to defending the Corvair because all cars can explode under the right circumstances.

This shortcoming in Rails is so ridiculous that it literally leaves me agog that anyone would even consider using it for anything but the simplest of toys.

One of the things I find tremendously funny is how the Python community is always criticized for having too many web frameworks. The core concepts of Rails has been reimplemented in Python at least a dozen times. Apparently it just isn't that difficult to do. Apparently it's not difficult to write a threaded or asynchronous server either, since all of these servers were able to handle multiple simultaneous requests just fine.

Seriously, if you love Ruby, I can understand. But Rails? How far must someone put their head up their own ass in order to be able to overlook how fundamentally flawed it is?

You know what? I don't want to know. I only hope that Igor doesn't put too much work into adding this retarded "feature" to Nginx.



0 comments Leave a comment