Thursday 15 September 2011

what is the fasted way to call Lua from C? -


I have an HTTP server that needs to handle HTTP requests from the Lua code. From C code, I say some Lua CiCi like this (comes with idea):

  lua_State * l = luaL_newstate (); LuaL_openlibs (L); LuaL_loadfile (L, "some.lua"); Lua_pikol (L, 0, 0, 0); / * Preload * / lua_getglobal (L, "handle"); Lua_pushstring (L, "http_request"); Lua_pikol (L, 1, 1, 0); Lua_close (l);   

This bunch of code is run for every HTTP request. In the context of the multi-thread worker reference, this code has a fairly significant display cost (20000tps to 100tps). I'm surprised that is a more effective way to call the call code from C < / Strong>?


Update

When I comment on all these LuaC API calls, then I have 20000 tons I can do the position. But when this API is calling, then make some changes to 100 TPS some.lua ( to delete call, only load an empty load file), then 15000 About TPS comes performance.

So, on the leash, the API calling cost will be about 5000 TPS, how fast will this API be called?

Use a thread-safe queue for the state of Louis and in line with an infinite loop, the state Pop up. If the queue is empty, then state the state that is triggered when it enters the queue. I recommend Luajit because it will optimize the raw threading API call to go to C-speed.

Unless you are handling HTTP requests in large quantities, this will not give you much benefits (as told by DSIN).

Note: This approach involves the reuse of the Luah states for many requests. If this is a security problem, then you may end up with a session ending with some luja states I can not ... but I'm not sure. (This would be an interesting experiment in state-client partnership! You can use the state of Luas to capture the entire session of the user and then start a new request again from sleep ... which will be faster .)

No comments:

Post a Comment