lua-users home
lua-l archive

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


On Thursday 15 February 2007, gary ng wrote:
> Initially, I want to make it a coroutine based
> system(may be copas). But I run into a problem which I
> don't know how to solve(thus the multi-process
> approach). I am writing a relay service which needs
> lazy write on the receiving end(return to the client
> as "done" asap) then on the real send/retreive end
> doing the real work which can take quite some time.
> And the HTTP server in question don't support stream
> mode. I don't want any of these worker thread stalled
> the whole thing till it is done.

if you do your delayed write in chunks you could still use copas and not stall 
the whole thing.

or, if you'd like to use threads, try the HelperThreadsToolkit 
(http://luaforge.net/projects/helper-threads/).  it has a copas-like 
scheduler that runs Lua code cooperatively (with coroutines), but manages a 
variable number of helper threads to execute HTT-enabled C code.  i have 
sample (but usable) modules for TCP and file I/O.

i was able to use them to write a Xavante-like web server; if you recall, one 
of the big differences between Apache 1.3 and 2.0 was its cooperative 
scheduling with "worker threads" that do most of the work.  HTT does a 
similar thing

-- 
Javier

Attachment: pgpLAS5_pOi3_.pgp
Description: PGP signature