Hi Dave,

On Mon, Dec 02, 2019 at 10:12:27AM -0600, Dave Chiluk wrote:
> Since 2.0 nbproc and nbthreads are now mutually exclusive, are there
> any ways to make lua multi-threaded?

Unfortunately no. Lua itself is inherently single-threaded and
even when you believe you're using multi-threading, you end up
on a big lock around all the engine that serializes everything.

>From what I've found, there were several attempts to make Lua support
preemptive threads, but most of them had huge limitations like not
sharing anything (pointless already), they were also limited to older
versions like 5.0 or 5.1.

With this said, I can easily understand that something light and fast
like Lua is hard to port to threads without losing all of its benefits.

Are your really using it so much that it becomes a bottleneck ? I find
this quite surprizing. If so, did you find any single part responsible
for most of the CPU usage ? Then do you think that by moving a few of
it to native code (sample fetches, converters set into variables), it
could improve the situation ? Maybe you should try a trick consisting
in setting tune.lua.forced-yield to a lower value (the default being
10000) so that it executes much less instructions at once, leaving more
room for other threads to take a share of the CPU. But in any case at
a given instant you will definitely have only one thread executing
Lua code. If at least you can make sure that others are not waiting
too much and find other things to do with the rest of haproxy, maybe
that could improve the efficiency of your program already.

Regards,
Willy

Reply via email to