lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Apr 12, 2010 at 7:57 PM, Matthew Wild <mwild1@gmail.com> wrote:
> On 13/04/10 00:48, Alexander Gladysh wrote:
>>
>> Hi, list!
>>
>> I see that Prosody project has updated sources of lua_signal library.
>>
>> http://github.com/bjc/prosody/blob/master/util-src/signal.c
>>
>> Is it possible to merge these changes back into the original library?
>>
>
> We already sent the changes as a patch to Patrick (because we're good guys).
>
> Though I don't think he used our patch verbatim, Patrick incorporated our
> feedback (because he's also good). He produced a new release and also
> relocated it to http://batbytes.com/lua-signal/ .
>
> However Prosody hasn't switched, and won't be just yet. The new lua-signal
> is changed somewhat, and has a debug hook permanently set. Though this
> wouldn't bother most applications, it bothers us (we both use debug hooks
> for debugging, and well, we're a realtime network server and it badly hurts
> throughput). Patrick indicated that he would be happy to amend the official
> lua-signal to reflect our concerns, but to the best of my knowledge has not
> yet done so. We'll likely switch to the official version when it includes
> these changes.

As I've told Matthew but will also state here. The crux of the problem
is we cannot set the hook on the running Lua thread. Before we would
save the thread that called signal() and set the hook on it when a
signal is received. This leaves us with the problem of that thread
either (a) being garbage collected or (b) not running again for some
indeterminate amount of time. Despite this being a signal handling
library, I felt this type of unpredictable behavior was unsuitable
(heh).

The only way to "solve" it was to set a debug hook that is run
periodically for all threads (by setting it on the main thread, which
we hope opened the library). My own benchmarks showed a ~5% increase
in runtime. I felt this was small enough to be ok. I acknowledge there
are other legitimate uses for hooks and the change does not play nice
with them.

I will end up reverting the change to have the debug hook set only on
signal receipt but it leaves me dissatisfied. (It would be nice if the
hook system were a global interpreter hook so this hook propagation
would be unnecessary and simply having a valid thread reference
guarantees the ability to set a hook on any running thread in the
global state.)

-- 
- Patrick Donnelly