[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: The memory usage in LUA intensive calling appz
- From: "Zdenek Stangl" <ptaczek@...>
- Date: Wed, 8 Jan 2003 12:05:50 +0100
"Thatcher Ulrich" <tu@tulrich.com> píse v diskusním príspevku
20030108024121.GH1032@tulrich.com">news:20030108024121.GH1032@tulrich.com...
> On Jan 08, 2003 at 02:42 +0100, Zdenek Stangl wrote:
> > Hello,
> >
> > Im new to this list. I've read few posts on memory leaking and garbage
> > collecting. Now I have just one question: Is it possible to get growing
> > memory usage in application that calls frequently lua script functions,
> > pushing new tables with strings and cfunctions ? Freqently = up to
50-times
> > per second.
>
> Yes, absolutely, if you generate new data that remains accessible.
> For example:
>
> ----
>
> history = {}
>
> function handle_request(req)
> -- req is a request to be served
>
> -- save req in the history buffer
> tinsert(history, req)
>
> do_the_actual_work(req)
> end
>
> ----
>
> If do_command() gets called repeatedly, the history table will keep
> growing and consuming memory, which can't be collected, because it's
> still reachable. If instead you periodically do "history = {}" to
> make the old data unreachable, or you don't use the history table at
> all, and don't otherwise keep links to old data, the garbage collector
> should be reclaiming that memory.
>
> The symptoms you describe sound a lot like you're somehow keeping
> links to generated data.
>
> --
> Thatcher Ulrich
> http://tulrich.com
>
Thanx for quick reply.
The problem is probably somewhere else. If the lua_getgccount returns the
total bytes used by the lua vm then everything is ok. Each script in my
simple server appz eats about 40-60Kb of memory. But the windows task
manager (or performance monitor) shows growing trend of ram usage. I've
checked the appz with MemorySleuth and BoundsChecker and didn't found any
repeating memory/resource leaks.
Also I tried to call lua_setgcthreshold(L,0) every 10 seconds and Im also
taking care of stack. The whole thing is being mysterious. If I turn off the
scripting then no memory rising occurs.
What Im doing are 2 simple things:
1) In my C++ code I have few global functions that are registered to the lua
at the start and are called by the script(s). They are mostly functions that
receive one or two strings and post them to another users connected to the
server. These functions are registered only once at the lua vm
initialization.
2) The server appz invokes specific LUA functions when new data are received
from somebody or when new user connects to the server. When such action
occurs I need to pass the user information and the data to the script as
arguments of global function.
Im doing it in these steps:
- First I push the desired lua function name on the stack then by
lua_getglobal(L, fnName) and lua_isnil(L, 1) test if this function exists in
the script.
- If there is no such function in the script, I pop the fnName from the
stack and return.
- If there is such function I push a new table on the stack with about 7
fileds that contains strings and another cfunctions. In fact Im creating a
pseudo user object with methods and pass it as argument to the lua function
along with data received from that user.
The script then preceses the data and uses the pushed table as object of
user with methods for sending text data back to the user.
Conclusion:
- I think I can be sure there are no leaks in my appz.
- Also I think that no data pushed to lua remains referenced - all strings
pushed by C are duplicated before push and freed before return. Of course Im
pushing also cfunctions that 'lives' along with the application.
- The getgccount shows low memory usage.
- The memory usage grow don't occurs when scripting is off
Any help or insight is apreciated.
Zdenek.