On Mon, Mar 15, 2010 at 3:35 AM, gary ng <garyng2...@yahoo.com> wrote: > > > --- On Mon, 3/15/10, Chad Phillips -- Apartment Lines > <c...@apartmentlines.com> wrote: >> i'm pretty sure the reason this appears so badly with >> FreeSWITCH is because the FreeSWITCH master process uses a >> new instance of Lua any time it gets a call to run a Lua >> script. since the master FreeSWITCH process runs >> continuously, the memory leak builds up. i'm guessing >> for most use cases, the Lua script leveraging LuaSQL is >> called directly and then the process terminates, so the leak >> never builds up. > I reported this problem long ago for the ring usage of lua in Kepler. My > conclusion back then was, either use cgilua(i.e. as you mentioned one process > per request) or use one lua process without ring and use Lua's function table > to isolate requests. Both solution worked for me so I no longer pursuit on > the proper solution for the mysql client issue. >
I am still not understanding how the memory leak would accumulate. Lua states are not OS processes, and from what I read in the documentation you should call mysql_library_init/mysql_library_end on a per-OS-process basis (and mysql_library_init is called lazily by mysql_init the first time you call mysql_init). For the MySQL client I would assume it makes no difference whether you have different Lua states or not. See the "[16 May 2006 9:26] Alexander Barkov" message on http://bugs.mysql.com/bug.php?id=7619, for example. The same usage pattern as LuaSQL, no increasing memory consumption. I just tried a loop like this: while true do state = rings.new() rings.dostring[[ require "luasql.mysql" env = luasql.mysql() conn = env:connect(<connection data>) conn:close() cursor = conn:execute("select * from foo") while cursor:fetch() do end env:close() ]] state:close() end I left this running for 1M iterations and memory usage was constant... Maybe there is a real real memory leak somewhere in libmysqlclient that needs to be flushed away by doing a mysql_library_close now and then, and it is triggered by different conditions... -- Fabio Mascarenhas _______________________________________________ Kepler-Project mailing list Kepler-Project@lists.luaforge.net http://lists.luaforge.net/cgi-bin/mailman/listinfo/kepler-project http://www.keplerproject.org/