Git Product home page Git Product logo

luafcgid2's Introduction

Summary

luafcgid2 is a multithreaded FastCGI server that runs under BSD/Linux. It manages a number of independent, persistent Lua states, that are then loaded with Lua scripts from the file system. These scripts are loaded/initialized on demand, and held in memory for as long as possible. The Lua scripts are also allowed to interface with the FastCGI libraries: thus providing an extremely fast, streamlined and lightweight platform from which to develop web-centric apps in Lua.

License

See the LICENSE file included with the source code

Testing

All development testing is done with a Raspberry Pi Zero W.

Software:

  • Raspbian Lite - last stable release
  • nginx web server - last stable release
  • Lua 5.3 - last stable release

Prerequisites

  • Lua 5.3
  • libfcgi 2.4
  • libpthread

On a Raspberry Pi, simply run the following:

# sudo apt-get -y install libfcgi-dev liblua5.3-dev git make build-essential
# git clone --recursive [email protected]:EssGeeEich/luafcgid2.git
# cd luafcgid2
# make
# sudo make install install-daemon

You may need to tinker with the Makefile if you aren't using a Raspberry Pi.

Webserver (nginx):

Add the following lines to your /etc/nginx/sites-available/your-site-here in the server{} section:

location ~ \.lua$ {
	fastcgi_pass   unix:/var/tmp/luafcgid2.sock;
	fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
	include        fastcgi_params;
}

NOTE: make sure your root directive is set correctly

Design

luafcgid2 spawns and manages a number of worker threads that each contain an isolated blocking accept loop. The FastCGI libraries provide a connect queue for each worker thread so that transient load spikes can be handled with a minimum of fuss.

                  +---------------+                                
              +-->| worker thread |--+            +-------------+
+----------+  |   +---------------+  |            |   scripts   |
| luafcgid |--+                      +-- mutex -->| loaded into |
+----------+  |   +---------------+  |     |      |  Lua states |
     |        +-->| worker thread |--+     |      +-------------+
     |            +---------------+        |                
     |                                     |             
     +------------- housekeeping ----------+             

Lua is then introduced into the picture by created a shared Lua state for each Lua script that is requested. A script will be loaded multiple times. All scripts - including duplicates (clones) - are completely isolated from each other. After a state is initialized and loaded with a script, it is kept in memory forever. Each Lua VM is run within a worker thread as needed. The use of on-demand clones allows for multiple workers to run the same popular script. There is a configurable limit to the total number of Lua states that luafcgid will maintain. When this limit is reached, a new state gets generated at runtime.

luafcgid2's People

Contributors

snarkyclark avatar essgeeeich avatar andryblack avatar saltwaterc avatar likema avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.