httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Gruno <>
Subject Re: Default value of LuaScope in trunk mod_lua
Date Thu, 25 Apr 2013 15:10:13 GMT
On 04/25/2013 04:41 PM, Eric Covener wrote:
> On Thu, Apr 25, 2013 at 10:24 AM, Daniel Gruno <> wrote:
>> Hi dev@ people,
>> I'm thinking of changing the default value of LuaScope in trunk to
>> 'thread', as the current default, 'once', has a significant performance
>> impact (as I explained at ApacheCon). As Lua's garbage collector is
>> quite awesome (it's virtually impossible to leak memory unless you
>> deliberately do so), I don't see a reason why we should stick with
>> 'once' on threaded platforms, especially considering the overhead of
>> reloading libraries into the VMs if they are created and thrown away
>> after each request. I would also like for this to get backported to 2.4
>> at some point, which is why I'm throwing you this email as a heads up.
>> Thoughts? ideas? heckling?
> You mentioned before some corner case with scripts relying on
> globals/statics/??? that this would affect. Can you give an idea of
> how corner that is?
There could be some issues where a (bad bad bad) programmer relies on
variables being undefined or set to a default when the script enters a
function, but any respectful Lua programmer knows you *always use local
variables*. The 'problem' arises when two scripts share the same VM, and
the owner of script A assumes that he is in full control of global
variables, but script B does something stupid and changes, fx. os.time
to nil. In this case, you'd need to reload the os library with "require

However, on the plus side, you have
1) Faster loading of all pages, since the VM doesn't need to be created
2) Less malloc/free since your libraries are only loaded once
3) you can set persistent values that you only need to generate once per
thread, fx something that requires a lot of cpu cycles.
4) You only need to load and compile scripts from disk once (unless they
changed since last compilation)

So yes, there are caveats, but I personally consider it insignificant
compared to the big performance boost it gives you, and I don't consider
the caveats big enough to warrant 'once' as the default scope. But as I
said, comments/thoughts are most welcome, and I will take them under
advisement :)

With regards,

View raw message