On Mar 31, 2008, at 8:12 PM, Graham Wakefield wrote:
I solved the problem (see the other posts). It was my fault
No, I don't want to use multiple threads. Only for time consuming functions. But those functions will not have anything to do with Lua. In fact, all the server is single threaded (accepting connections, serialize/deserialize messages, invoking Lua function upon messages receive, etc). If one user wants to have access to the database, he will put a message in a special queue. The working threads will pick the work load from there, process it and put the results in another queue. last operation that a thread is doing is to signal "job completed" to the main thread who in turn picks up the result from the queue and do whatever there is to do with it. Including resume a yielded lua_State. So, the Lua script writer doesn't have to know anything about the internals of the database layer. All he has to know is the type and connecting string to the database. And, of course, to write the SQL in that particular dialect of SQL.
Some inside information :)
Is a RTMP server written entirely in c++ with applications written by the final user in Lua. The server is using kqueue for networking but not only for that. Thread signaling is made using pipes that in turn are managed by kqueue. Very clean design that is offering robustness since we don't do and shared resource protection (no more race conditions).
I've chosen Lua for scripting RTMP applications because:
-- very light-weight
-- small memory footprint
-- offers built in notion of "session" through coroutines (adopting python for this, was a disaster!!!)
-- incredibly easy syntax. I've started to learn Lua syntax. But soon I just found out that I already know Lua :).
So any technical guy can learn it in a matter of hours. (Or find out that he already knows Lua :) )
-- ability to load external libraries. Of course, python has this too, but try to make an wrapper for python without swig (the horror! the horror!).
Not to mention that having that *.py generated by swig was stepping on my bare nerves!!!
-- variable number of arguments and return values and the ease of use. Didn't bother to search if the python has this too... :)
-- is very fast!
So, thank you for Lua!!!!
I'll wait to pull the server in a semi usable state. After that, I think I will make it publicly available... Or parts of it...