https://bugzilla.wikimedia.org/show_bug.cgi?id=70177
Ori Livneh <o...@wikimedia.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|Normal |High CC| |aschulz4...@gmail.com See Also| |https://bugzilla.wikimedia. | |org/show_bug.cgi?id=68413 Assignee|wikibugs-l@lists.wikimedia. |tstarl...@wikimedia.org |org | Summary|Lua takes a lot more CPU |The way LuaSandbox measures |time with HHVM jobrunners |CPU time is not thread-safe --- Comment #1 from Ori Livneh <o...@wikimedia.org> --- The issue is that LuaSandbox is not thread-safe. The figure you're seeing conflates the CPU time of several concurrent threads of execution. * LuaSandbox uses CLOCK_PROCESS_CPUTIME_ID to measure time, but CLOCK_PROCESS_CPUTIME_ID measures CPU time consumed by all threads of the calling process. * LuaSandbox requests to be notified with a SIGEV_SIGNAL upon timer expiration, but at any point in time, only only one such signal is queued per timer per process. * LuaSandbox uses the sigprocmask() system call to block signals, but its behavior in a multithreaded process is unspecified. pthread_sigmask() must be used instead. * When the normal or emergency timers are stopped, any queued SIGEV_SIGNAL for the entire process is flushed. * When multiple threads are executing concurrently, the timer for the entire process is repeatedly re-armed (i.e., the exiration is reset). * Confusingly, LUASANDBOX_G(signal_handler_installed) is thread-local, not global. This means every thread calls luasandbox_timer_install_handler. The latter caches the old handler in another thread-local variable and reinstalls it when LuaSandbox is deactivating. When LuaSandbox is active in multiple threads, individual threads end up re-installing each other's signal handlers, keeping each other alive. The above applies specifically to the normal and emergency timers. The profiling feature has its own bag of thread-safety / reentrancy issues, which I propose we deal with in the context of bug 68413 rather than this bug. -- You are receiving this mail because: You are the assignee for the bug. You are on the CC list for the bug. _______________________________________________ Wikibugs-l mailing list Wikibugs-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikibugs-l