Hacker News new | comments | show | ask | jobs | submit login

Coroutines on a server...like OpenResty [1] (a package containing Nginx w/Lua integration)?

The example "asynchronous get" becomes something like:

    local myObject = query{ id=3244 };
The query function can be written to handle a cache lookup, a database query that gets stored in the cache, and any other logging you want, because Lua has coroutines. All I/O that gets sent through the "ngx" query object (which can connect to local or remote ports) yields control to the main loop.

"query" is an example of a function you could create; its implementation (with a cache lookup) could look something like (yes, I use CouchDB...):

    function query(t)

      local result = ngx.location.capture(  "/cacheserver/id:"..t.id );
      if #result == 0 then
        result = ngx.location.capture(  "/couchdb/usertable/"..t.id );

      return result
I've heard reports of 50k+ connections/second on a VPS running Nginx, LuaJit, and the LuaNginxModule, and on my low-end VPS it easily handles 2000+ connections per second (with CouchDB queries) with no more than 250ms latency. Actually, that was as many connections I could send at it, so it may be able to handle a lot more.

[1] http://openresty.org/

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact