lua-users home
lua-l archive

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

Bogdan Harjoc wrote:
> Robert Raschke wrote:
>> Markus wrote:
>>> However, I do agree with Stefan, that a million threads is probably
>>> not the best known solution, whatever the problem... But ofcourse I
>>> am happy to be shown wrong here!
>> Telco land has needs for enormous amounts of concurrency.  Have a
>> look at Erlang ( for one way of dealing with
>> that. 
> Yours was the first on-topic reply, although I suppose I should have
> given more details if I was expecting on-topic repies. Yes, I am
> (aiming at) simulating 1 million voip clients, each placing a
> phonecall from time to time (maybe you 'guessed' by looking at the
> email address ?).    
> And the reason I (assumed I) needed one thread per client was because
> I needed to be able to express client behaviour in a natural way (Lua
> coroutines + an event 
> loop being a good candidate for doing this).

What you're trying to do is called a Multi-Agent System (MAS) [1]. In
many cases cooperative multi-threading is the best solution to MAS
problems, and coroutine are an example of cooperative multi-threading
systems. On the other hand Lua coroutines were designed as a general
programming tool, whereas getting millions of concurrent threads require
some specialized models (among other things to solve the memory problem
you encountered). Maybe you can have a look at Erlang, which was
designed for the kind of problems you have. And if it doesn't fit you're
probably better writing your own high level domain specific language,
with a kind of virtual machine to run it (the virtual machine can be
implemented in Lua and use coroutines, but maybe not one per agent).