4.9.3 FastCGI Deployment

##
4.9.3 `FastCGI` Deployment

The `albatross.fcgiapp` module contains a `Request` class to allow you to deploy your application using `FastCGI` 4.2.

Applications deployed via CGI often perform poorly under load, because the application is started afresh to service each client request, and the start-up time can account for a significant proportion of request service time. `FastCGI` attempts to address this by turning the application into a persistent server that can handle many client requests.

Unlike `mod_python`, where applications run within the web server, `FastCGI` applications communicate with the web server via a platform-independent socket protocol. This improves security and the resilience of the web service.

To deploy your application via `FastCGI` and Apache, you need to configure Apache to load `mod_fastcgi.so`, configure it to start your script as a `FastCGI` server, and use the `albatross.fcgiapp` `Request` class in your application. As an example of Apache configuration:

    LoadModule fastcgi_module /usr/lib/apache/1.3/mod_fastcgi.so

    <IfModule mod_fastcgi.c>
        <Directory /usr/lib/cgi-bin/application/>
            AddHandler fastcgi-script py
            Options +ExecCGI
        </Directory>
    </IfModule>

And the application main-line:

    #!/usr/bin/python
    from albatross.fcgiapp import Request, running

    class Application(...):
        ...

    app = Application()
    if __name__ == '__main__':
        while running():
            app.run(Request())

#### Footnotes

...FastCGI 4.2
  For more information on `FastCGI`, including installation instructions, see http://www.fastcgi.com/.