lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Is lua a suitable language for this target domain?

We've successfully deployed Lua in a production environment serving
hundreds of users from a single PC (a run-of-the-mill Core 2 Duo with
2 GB RAM, running Windows 2008 Server).
During our stress tests, we saw it handle it serve high-single-digits
thousands of clients. It is running smoothly, without crashes or
memory leaks, for months now; the machine has been rebooted once in
that period for external to our code reasons.

The select() code in luasocket becomes a problem before Lua itself
does; we made some small fixes to make it more Windows-friendly (we
provided our changes to Diego Nehab, the author of luasocket, I can
also send the small patch to anyone interested in serving 100+ clients
on Windows). Also, on Windows, you need to compile with a #define
before including the system headers to listen on thousands of ports.

We ran into some kind of soft performance limit with listening with
select() to too many sockets in the same process - on the order of
thousands. Our architecture is meant to "scale out", and we simply ran
more instances of our server code on the same machine, each serving
e.g. 1000 clients - this worked around the problem.

The workload consists of deserializing incoming packets, updating
in-memory data structures (Lua tables, of course), occasional
cryptographical computations (handled via libgmp in C), resending the
data to other clients, and occasionally writing out journal and log
files.

More performance can probably be extracted if luasocket is implemented
via "more navite" OS-specific mechanisms, e.g. IOCP on Windows.

My gut feeling is that nowadays it's quite possible to achieve the
goal of the C10K paper, that is, to serve 10k clients from a single
machine - in Lua. Don't let the small problem of having to serve
thousands of clients drive you into using an inferior language!

(Also, don't believe the "you can't really run servers on Windows"
conventional wisdom :-) )

Best regards,
Ivan-Assen Ivanov
CTO, Haemimont Games