Prev: Next: Up: Top[Contents][Index]


8 Extending pound functionality with Lua

Lua is a lightweight extension language developed at the Pontifical Catholic University of Rio de Janeiro. Functions and modules written in Lua can be used to implement new features in pound without the need to modify its sources and recompile it.10

Lua source files can be loaded using two distinct modes: per-thread and global. In per-thread mode, each Lua file is loaded into each worker thread separately. This is the default. In global mode sources are loaded only once and exist in one copy, available for use in all threads. No matter what mode is used, Lua sources are read and interpreted only once, at program startup.

The main advantage of per-thread mode is speed. Each thread runs its own copy of Lua interpreter and doesn’t have to synchronize its actions with other threads. Its disadvantage is a bit higher memory usage.

Sources loaded in global mode reside in one interpreter, common for all threads. Consequently, before calling a Lua function, the thread must lock the interpreter for its use, and unlock it afterwards. While the interpreter is in use by a single thread, remaining threads must wait for it to be released in order to use it. This results in certain performance penalty.

Both modes can be used together. No matter which mode is used, Lua functions sharing the same mode can use a special global variable to exchange data between them, if they are called in different stages of request processing. This way, for example, a Lua test can pass its results to the Lua backend.


Footnotes

(10)

To check if the binary supports Lua, run pound -V and examine its output.


Prev: Next: Up: Top[Contents][Index]