fastcgi really is … fast

I’m still working on tweaking space paranoids so it is a bit meaner and leaner, and one thing I ran into this morning is that trac was crawling. I started looking at my options to see what I could do better.

First I tweaked apache a little bit to not use as much memory or threads on startup, which really didn’t help that much. Then I poked around with tracd, and that was incredibly faster than running it as CGI scripts through apache. The only problem was, I don’t want to run two daemons if I don’t have to, especially on port 80. Technically, I could have them both listen on different IP addresses, but I’d still have to do something funky like setup a subdomain for one of them, like trac.spaceparanoids.org. Meh.

lighttpd really isn’t an option for the same reason, though I’ve heard good things about it. I’d like to try it out some day, but for now I like apache a lot, and I’ll stick with that.

The next thing I wanted to try out was fastcgi. I had played with it before, but always had funky errors I couldn’t figure out with the environment variables. This time I actually read the documentation, and now all is well.

To set it up on Gentoo, this is all you have to do. Emerge trac with the ‘fastcgi’ use flag, and then also emerge mod_fastcgi. Add “-D FASTCGI” to /etc/conf.d/apache2 so it will parse and load /etc/apache2/modules.d/20_mod_fastcgi.conf. Then, setup your stuff for trac in your config files as you normally would. Since I’m using more than one trac installation, I have /trac pointing to the fcgi script directly with this: ScriptAlias /trac /var/www/spaceparanoids.org/cgi-bin/trac.fcgi

Finally, edit that trac.fcgi file manually (so sayeth the docs), and add these lines to the top:

import os
os.environ['TRAC_ENV_PARENT_DIR'] = "/path/to/project/parent/dir"

Then I restart apache, and everything is running gloriously faster. I couldn’t be happier.

Of course, my SVN repositories still aren’t setup correctly, but I’ll fix that another day.

3 comments on “fastcgi really is … fast

  1. Chewi

    I left Apache for lighttpd a few months back and haven’t looked back since. Seriously, check it out. Some people like to control their FastCGI applications independently of the server. You can use spawn-fcgi for this but the init script provided with lighttpd sucks. I wrote a much better one that can be repeatedly symlinked for each application you want. It is easy to setup and works really well but the bug report for it was brushed aside when the independent spawn-fcgi package was obsoleted in favour of the version included with lighttpd. I’ve since reopened it but it’s not been looked at yet. )-:

    http://bugs.gentoo.org/show_bug.cgi?id=149467

    Reply
  2. Björn Michaelsen

    Well, lighttpd is lean and mean. I used it for quite some time.
    But:
    – Its configuration sucks.
    – Someday you might need to provide WebDAV access to SVN and then you need apache anyway
    – apaches mod_python is easy to setup and also rather fast …

    Reply

Leave a Reply