|
Very cool, but it's too bad you have to deal with all that to begin with. I've been using LuaJIT embedded in Nginx (LuaNginxModule). Lua supports coroutines, so a function can just yield. Here's a brief example: -- Query a database using an http backend.
-- Yields and handles other requests until the reply is complete.
local record = util.getUserRecord(userId)
-- Send some text to the client. Yields control while
-- the actual transfer is in progress.
ngx.print( "Result=" )
-- Send the result, encoded as JSON, to the client
-- Again, this call doesn't block the server.
ngx.print( cjson.encode(result) )
With code like the above I can easily handle into the thousands of concurrent connections per second on the lowest end Linode VPS node available, with barely any load on the box -- and I'm told it should be able to handle 40k+ connections per second, if I were to do any tuning. Oh, and I have only 512Mb of RAM, which it doesn't even get close to under load. And the longest request took less than 500ms at high load.I've been using OpenResty [1] which has the Lua module and a bunch of others all configured together. Works great, and I can't complain about the performance. Someday I'm sure I'll hand the maintenance of this off, and then I might regret not using one of the "popular" frameworks. But the code is SO straightforward using this stack -- and what I'm using it for is so simple -- I think not. [1] http://openresty.org/ |