[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Garbage collection best practices
- From: Sean Conner <sean@...>
- Date: Wed, 27 Jul 2011 11:26:24 -0400
It was thus said that the Great Antonio Vieiro once stated:
> Hi all,
>
> I did some load tests on a lua program (a *C* program that uses
> different Lua VMs, each on its own thread) and I've seen memory
> increasing to around 1Gb (possibly my Window's memory limit or
> something), and then falling quickly to 64Mb or so.
>
> I've been looking at the LuaFAQ but I couldn't find an appropriate
> answer, so here I go:
>
> a) Can I limit the max memory a Lua VM uses? How?
Two ways. The first way is to use an operating system specific method to
limit the amount of memory a process ueses. Under Unix, this would be the
ulimit command (or the setrlimit() function from C). There may be a Windows
equivalent way of doing so, but I don't know what it would be.
The second way is to use lua_setallocf() to register a custom memory
allocator that will limit the amount of memory Lua will use. You will need
to do this for each Lua state you create.
> b) If my C program serves "requests", shall I...
>
> b.1) Invoke lua_gc(L, LUA_GCCOLLECT) after each request?
> b.2) b.1 is too heavy, I whould do the same with LUA_GCSTEP
> b.3) I shouldn't modify GC default settings.
> b.4) Call lua_gc with LUA_GCCOLLECT after X requests served
That's something you'll have to measure. I have a syslog daemon [1] I
wrote that uses Lua to process each message. One server it's been install
on has been running for 172 days and it's using less memory than any other
process on the box and I haven't tweaked the memory usage or called the
garbage collector manually. Your usage case may be different.
-spc
[1] http://www.conman.org/software/syslogintr/