If you came from other object oriented languages, you may find lua for web development a strange choice.

Well, you have to consider one thing when exploring Lua: it is fast, really fast and consume very few resources.

The uWSGI plugin allows you to write web applications in lua, but another purpose (if not the main one) is using Lua to
extend the uWSGI server (and your application) using the signals framework, the rpc subsystem or the simple hooks engine.

If you have slow-area in your code (independently by the language used) consider rewriting them in Lua (before dealing with C)
and use uWSGI to safely call them.

One of the most exciting feature of Lua are coroutines (cooperative
multithreading) support. uWSGI can benefit from this using its async engine. The
Lua plugin will initialize a lua_State for every async core. We will use a
CPU-bound version of our pippo.lua to test it:

And just like that, you can manage 8 concurrent requests within a single worker!

Lua coroutines do not work over C stacks (meaning you cannot manage them with your C code), but thanks to uGreen – uWSGI Green Threads (the uWSGI official coroutine/greenthread engine)
you can bypass this limit.

Thanks to uGreen you can use the uWSGI async API in your Lua apps and gain a very high level of concurrency.

The Lua plugin is “thread-safe” as uWSGI maps a lua_State to each internal
pthread. For example you can run the Sputnik wiki engine very easily. Use
LuaRocks to install Sputnik and versium-sqlite3. A database-backed storage
is required as the default filesystem storage does not support being accessed
by multiple interpreters concurrently. Create a wsapi compliant file:

As we all know, uWSGI is parsimonious with memory. Memory is a precious
resource. Do not trust software that does not care for your memory! The Lua
garbage collector is automatically called (by default) after each request.

You can tune the frequency of the GC call with the --lua-gc-freq<n> option, where n
is the number of requests after the GC will be called:

[uwsgi]plugins=luasocket=127.0.0.1:3031processes=4master=truelua=foobar.lua; run the gc every 10 requestslua-gc-freq=10