CGI, FastCGI, whatever - what are they?
There are many ways to connect your application to web-server. Most common are CGI and FastCGI modes and running application as an HTTP server.
CGI mode
CGI which stands for Common Gateway Interface was the first way to launch external app from webserver and get something done. For each client request, a new application was spawned, did some calculations and any given response was forwared to client.
PROS:
- If you change application, it will give a new result on next request (on page refresh, for example). Very useful for web-development.
- If there are several requests at the same time, then several applications are spawned and clients (4 and 5) do not need to wait until previous client gets response (3).
CONS:
- Very very very slow. For each request system must launch a new copy of application, load every library, load source code and compile it (for languages like JavaScript, Perl, Python etc), connect to database etc. This is a tremendous amount of time.
Dedicated FastCGI mode
FastCGI is a way to run an application continiously so that it would wait in infinite cycle and respond to requests, one after another. An example given is more relevant to languages like C++ and Perl, since NodeJS has (only some) parallelism emulation.
PROS:
- Very fast. Application load, code parsing etc are only done once and after that system runs faster then light.
CONS:
- If you made any changes to application, you will need to restart it to get updated results. Very inconvenient for development.
- If there are several requests at the same time, they are queued and application will start working on new request (4) only when it send response on previous request (3).
- Note for NODEJS: since node runs in event loop something like green threads, it can start working on new request (4) but ONLY IF it is in wait state and not busy with anything else. For example, if request 3 needs some data from database, SQL request to database was sent AND not yet received, then node can start work on new request (4), but if current requests needs some calculations inside NODEJS (okay, we are calculating number PI in javascript or generating a huge html table), then new request (4) must wait until we are done.
Apache2-launched FastCGI mode
FastCGI can be started by developer (or system or something) or can be dynamically spawned/killed by web-server, for example, apache. In this case, if we are already calculating PI number inside current request 3, we can still spawn a new process and start another calculation round on another process core.