[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [Sandboxed Lua] Limit execution time, loop iterations and memory usage
- From: Bertrand Mansion <lua@...>
- Date: Wed, 9 Jun 2010 11:31:43 +0200
In my experiment on http://trylua.mamasam.com I use the Lua extension
for PHP which you can find only in the php SVN because it hasn't been
released yet. This way, PHP can control the resources used by Lua and
in case the values set for max_execution_time or memory_limit are
exceeded, trigger an error which you can catch to display a nice error
message and end the script correctly. If you are proficient in C, this
Lua extension for PHP needs some love I think:
Then there is my version which is probably all wrong since I am not an expert:
On Wed, Jun 9, 2010 at 10:35 AM, <email@example.com> wrote:
> Thanks you for all your answers, I managed to limit CPU time and memory using the "ulimit" command.
> But now there is a performance issue. I ran some tests on the current testing system and found out that launching the Lua parser (from my PHP script) takes around 0.02 seconds, almost exactly the time it takes to calculate the sine 100.000 times. Since the sandboxed Lua is supposed to be ran a few times for each PHP site parsed, this may cause serious performance problems (0.02s for intepreter + 0.02s for script = 0.04s, 0.04s * 10 = 0.4s, and this is just the Lua part, without any MySQL or PHP).
> Is there any possibility of running the interpreter all the time and just sending it commands which scripts to execute and then stream the output back to my PHP script? This would eliminate the need to start the interpreter again and again.
> Your help would really be appreciated,
> Lennart Moltrecht
> -----Ursprüngliche Nachricht-----
> Von: "Patrick Donnelly" <firstname.lastname@example.org>
> Gesendet: Dienstag, 8 Juni, 2010 16:33
> An: "Lua list" <email@example.com>
> Betreff: Re: [Sandboxed Lua] Limit execution time, loop iterations and memory usage
> On Tue, Jun 8, 2010 at 10:30 AM, Kurt Nordstrom
> <firstname.lastname@example.org> wrote:
>> Also, look at the debugging hooks in the C API.
>> I'd be interested in seeing a good solution to limiting memory
> There is a good solution, give Lua an allocator that has a limit on
> the amount of memory .
>  http://www.lua.org/manual/5.1/manual.html#lua_Alloc
> - Patrick Donnelly