Computer Diary

    "God grant me the serenity to accept the things I cannot change; courage to change the things I can; and wisdom to know the difference."

    Reinhold Niebuhr

    Here my little rant and praise place, where the daily experiences of my programming work are expressed. I publish them with the idea that others might find it useful and benefit from it.

    Rebirth of FastCGI
    last edited 2009/04/16 08:57 (*)

    Since I switched from to , as mentioned in How To Save 300MB RAM, I got to an old buddy I almost forgot: FastCGI.


    use CGI;

    parse_arguments(); do_request(); exit();


    use FCGI;

    while(get_request()) { parse_arguments(); do_request(); } exit(); # probably never reached

    It's an internal (tcp or named socket) based sub-server process which handles the requests. Why should this be anything better than Apache with mod_php or mod_perl?

    Here some numbers, Intel P4 2.4GHz with linux-2.6.27-7-generic, running lighttpd/1.4.19:

    • perl-cgi: 18 requests/s or 55ms / request
    • perl-fcgi (via named socket): 240 requests/s or 4.1ms / request

    which makes about 13x speedup! It can be explained that the fcgi perl is already started and immediately handles the request - whereas a pure cgi has to load perl and then the cgi code as well.

    In order to use fcgi with lighttpd see at ModFastCGI , be sure you don't use the lighty-enable-mod as it only works for php, enable it by hand in your lighttpd.conf:

    • add "mod_fastcgi" into server.modules = ()
    • add fastcgi.server definition within your server definition


    I coded a fcgi test so after 100 or 1000 requests the while() loop would be exited - but it caused a few "500 internal error" at the client end: 1 error in 10,000-20,000 requests. In other words, to quit a fcgi causes internal errors within lighttpd for a busy web-site (@ 200 requests/s). Just a few errors you might say, but if you run something important I recommend you rather give /etc/init.d/lighttpd restart instead quitting the fcgi itself. Why? I do like to reset the fcgi because nobody is perfect, and perl might have or my fcgi code have memory leaks, and if you let it run for days and millions of requests the smallest memory leak will show up - that's why I personally prefer to reset a fcgi once a day.

    See also

    All posts or individual posts:

  • MetaFS - Dealing With Metadata the Proper Way (2013/12/14 01:00)
  • My Cellphones & Smartphone (2010-2013) (2013/09/02 23:15)
  • KDE / Kubuntu 12.04: 10+ years terrible GUI, A Systemic Problem of OSS (2013/04/27 12:18)
  • UNIX Man on Windows 7: VirtualBox + Ubuntu + LXC (2012/11/27 19:24)
  • Metadata - The Unresolved Mess (2012/07/10 20:59)
  • Cellphone Networks: Thieves, Insanity & Crap (2010/01/26 13:57)
  • MacOS-X for a UNIX Man with a PC (2009/09/26 20:43)
  • Windows XP for a UNIX Man (2009/09/22 18:28)
  • Server Counting (2009/05/18 11:50)
  • Automatically Geotag Photos without GPS (2009/04/22 08:28)
  • Rebirth of FastCGI (2009/04/15 17:17)
  • Online Advertisement & Income for Web-Site Owners (2009/03/18 22:10)
  • iPhone JavaScript Frameworks (aka Avoiding Objective-C) (2009/03/14 22:08)
  • Google - The Almighty Tracker & Advertising Blocking (2009/03/12 22:09)
  • How To Save 300MB RAM (2009/03/07 22:07)
  • Verbosity of Programming Languages (2009/03/06 22:06)
  • Problems with MacOSX (2009/03/03 22:03)
  • MacOSX: My First Steps (2009/02/24 09:57)
  • Catch 22 with HDD/DVD Recorder Medion Life (2009/02/24 09:27)
  • Kubuntu 8.1 as guest on VirtualBox MacOSX host (2009/02/24 01:33)
  • VirtualBox vs VMWare Fusion on MacOSX (2009/02/24 01:19)
  • SQL vs GREP with 230K lines (12MB) GeoLite (2009/02/23 20:10)
  • Kubuntu 8.1: Eye-Candy & Memory Waste (2009/01/24 09:57)
  • Firefox 2.0.x / 3.0.x - Memory Waste (2009/01/22 19:34)

    [ post new entry ] (only for administators)



    Tags: (separated by commas)

    Date (optional):



    Copyright 2007-2016, 2020-2023 © by René K. Müller <>
    Illustrations and graphics made with Inkscape, GIMP and Tgif