lua-users home
lua-l archive

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


On Mar 19, 2014, at 9:25 PM, 云风 <cloudwu@gmail.com> wrote:

> There are many lua vm (more then 10K) in one process in our system. We
> run all of them by a thread pool. It runs well except huge memory
> usage , because the same byte codes exist in each vm .
> 
> So I make a patch to lua 5.2.3 to share the same Proto objects among
> multiple lua vm [1].
> 
> It introduces a new api : void lua_clonefunction (lua_State *L, const void * fp)
> 
> We can get a lua function's pointer by lua_topointer first, and then
> pass it to lua_clonefunction to generate a new lua closure. The origin
> lua function can be in different  lua vm .
> 
> So we can put all the functions need to be share in an independent lua
> vm , and share them to other lua vm in the same process.
> 
> It can also accelerate the vm's bootstrap , because no parser or
> undump needed [2].
> 
> [1] https://gist.github.com/cloudwu/9656839
> [2] https://gist.github.com/cloudwu/9656890
> 
> -- 
> http://blog.codingnow.com
> 

This is something we’re also looking at for an in-house project, where many VM instances are running the same code and a significant (perhaps the MOST significant) amount of memory is consumed by loaded Lua bytecode.

—Tim