Hacker News new | ask | show | jobs
by transmit101 5033 days ago
Our main goal is to avoid passing requests upstream to Rails, which has massive performance penalties (TCP/IP, probably multiple database hits, web servers written in Ruby).

By keeping everything non-blocking and inside the Nginx event loop, and cutting the upstream out entirely, we are making a massive saving on each request. This definitely outweighs a small performance penalty incurred for using LuaJIT.

1 comments

I'm no Ruby expert, but I think the massive performance penalties of Rails are mostly not in the Ruby interpreter itself. Rails is a huge project and it does a lot of work.

It is possible that Ruby is impracticably slow in itself, I guess.

Keeping things non-blocking and inside the Nginx event loop doesn't specifically mean you have to use Lua, does it?

I'm not really sure what point you're trying to make. Are you saying that it's not desirable to reduce the load on your backend web servers?

I'm neither a Lua expert nor an evangelist, but my clear impression is that Lua is much more suited to embedding in a web server than Ruby or Python. On the Lua website it is described as "a powerful, fast, lightweight, embeddable scripting language" - that's not a description I would ascribe to either Ruby or Python. I also know that Lua has a long history of being embedded in games, embedded systems and other servers like Redis. Perhaps somebody more experienced in Lua can help me out here though.

In this case there seems to be good evidence that Lua is the right tool for the job.

One minor point- in your first comment you talk about interpreted Lua code, but this is not accurate because Lua can be compiled down to byte code before being loaded into Nginx.

Finally - "Embedding Python in a web server is quite doable". I would be interested to read a blog post about your experiments in this area ;)

I love Ruby. It is my favourite language by far. And I strongly believe that it is possible to do a Ruby implementation that is fast enough for most uses.

But current implementations are slow. And there are a lot of things in the language that makes a fast implementation hard. For example the fact that class definitions are executable and can be re-opened at any time, including by passing a string to eval(). They combine to make it extremely hard to make method calls fast. And since pretty much everything is method calls in Ruby, that's not good.

As an example, a Ruby implementation has to be able to deal with code that might overload the + method for integers, so even basic stuff like integer additions can't be statically inlined without precautions to handle cases like that.

I'd say for what they're doing, with tiny little rewrites in Nginx, Lua might be better suited - the Lua implementation is known for being extremely fast.