[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Nonblocking script execution
- From: Alexander Gladysh <agladysh@...>
- Date: Wed, 25 Feb 2009 01:22:58 +0300
On Wed, Feb 25, 2009 at 12:20 AM, Rob Hoelz <firstname.lastname@example.org> wrote:
> I did a quick, nonreliable test, and it took about 14 times longer with a C
Please share your test. My own quick unreliable test (attached) shows
slowdown closer to 1.05x, depending on instruction count, starting
from 100 instructions per hook. Maximum slowdown is 2.37 if hook is
called on every first instruction.
Note that in normal scenario instruction count in the hook is to be
greater than total count of instructions in the script.
Not setting hook
1 instruction, hook called 700000008 times
10 instructions, hook called 70000000 times
100 instructions, hook called 7000000 times
1000 instructions, hook called 700000 times
10000 instructions, hook called 70000 times
100000 instructions, hook called 7000 times
1000000 instructions, hook called 700 times
10000000 instructions, hook called 70 times
100000000 instructions, hook called 7 times
1000000000 instructions, hook called 0 times
> Also, another problem I thought of: what if the script makes an IO
> call?It'll still block...
Just do not expose blocking IO to untrusted script.
int g_counter = 0;
void handler(lua_State * L, lua_Debug * D)
int main(int argc, char ** argv)
int count = 0;
int result = 0;
lua_State * L = lua_open();
if (argc >= 2)
count = atoi(argv);
if (count <= 0)
printf("not setting hook\n");
printf("setting hook on %d instructions\n", count);
lua_sethook(L, handler, LUA_MASKCOUNT, count);
printf("running, please wait...\n");
"local j = 0\n"
"local f = function() j = j + 1 end\n"
"for i = 1, 1e8 do f() end\n"
) != 0
printf("Lua error: %s\n", lua_tostring(L, -1));
result = 1;
printf("done, hook called %d times\n", g_counter);