Server Modes

alsonkemp edited this page Sep 13, 2010 · 5 revisions

Turbinado can run in one of three modes:

  • HTTP
  • CGI
  • Fast CGI


In HTTP mode, Turbinado acts as a web server and will respond to HTTP requests on the specified port. HTTP mode is the best way to run
Turbinado because:

  • Turbinado is fastest in this mode because this is the mode it is designed to handle. (Fast)CGI requests are converted to HTTP requests internally.
  • In HTTP mode, Turbinado serves all requests from a flexible worker thread pool in a single process, so can handle many requests per second with
    a small memory footprint.
  • Since all workers share the same memory space, they also share the same dynamic code loader so compiling and loading of code only happens once.

Starting Turbinado in this mode and having it listen on port 3000 is simple:

turbinado -p 3000

Usually another webserver will be used to serve static content and will send dynamic requests to Turbinado. Apache would be configured as follows:

<VirtualHost *:80>
  DocumentRoot /var/www/turbinado-website/static
  <Directory "/var/www/turbinado-website/static">
     Options FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow from all
  # Don't do forward proxying
  ProxyRequests Off

  # Enable reverse proxying
  <Proxy *>
    Order deny,allow
    Allow from all

  RewriteEngine On
  # Rewrite "/" to "/Home"
  RewriteRule ^/$ /Home [R,L]

  # Let Apache serve static content
  RewriteRule (.*) $1 [L]

  # All other requests go to Turbinado
  ProxyPass        /
  ProxyPassReverse /

CGI and FastCGI

FastCGI mode is nearly as fast as HTTP mode, but is much less memory efficient since:

  • The GHC runtime and Turbinado environment are loaded multiple times on each server (once for each FCGI instance of Turbinado).
  • The dynamic code loader is not shared, so each instance of Turbinado compilesand loads code separately. This can take up to 10 seconds, so 5 FCGI instances would take nearly a minute to load dynamic code.

Using Apache and enabling the cgi and fastcgi modules (not fcgid), here is an example of how to serve requests using with Turbinado using CGI or FastCGI:

<VirtualHost *>
DocumentRoot /home/alson/projects/turbinado/static <Directory “/home/alson/projects/turbinado/static”> Options +FollowSymLinks +ExecCGI +Includes AddHandler cgi-script cgi AddHandler fastcgi-script fcgi AllowOverride None Order allow,deny Allow from all RewriteEngine On
  1. Serve static content if it exists.
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
    RewriteRule (.*) $1 [L]
  1. Otherwise send the request to the (F)CGI server
  2. CGI
    #RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/dispatch.cgi [QSA,L]
  3. FastCGI
    RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/dispatch.fcgi [QSA,L]