lighttpd で dispatch.fcgi を用意してcgiを動かす

この前、Debian lennyに lighttpd をインストールしたので、
今度はcgiを動かしてみる。手順は以下の通り。

1. aptitude install
$ sudo aptitude install libfcgi
2. /etc/lighttpd/lighttpd.confを編集

# mod_fastcgiをコメントアウトする
server.modules = (
    "mod_fastcgi", 
(略)
# fcgiを追加
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
(略)
fastcgi.server = ( ".cgi" =>
                     ( "localhost" =>
                         (
                           "min-procs" => 2,
                           "max-procs" => 3,
                           "socket" => "/tmp/lighttpd.socket",
                           "bin-path" => "/var/www/dispatch.fcgi",
                           "bin-environment" => ( "MT_HOME" => "/var/www/mt" )
                         )
                     )
                 )
3. lighttpdを再起動
$ sudo /etc/init.d/lighttpd restart
3. dispatch.fcgiを/var/www/に用意する

#!/usr/bin/perl
use strict;
use CGI::Fast;
use Embed::Persistent;
{   
    my $p = Embed::Persistent->new();
    while (new CGI::Fast) {
        my $filename = $ENV{SCRIPT_FILENAME};
        my $package = $p->valid_package_name($filename);
        my $mtime;
        if ($p->cached($filename, $package, \$mtime))
        {   
            eval {$package->handler;};
        }
        else
        {   
            $p->eval_file($ENV{SCRIPT_FILENAME});
        }
    }
}

4. cgiスクリプトを用意する(test.cgi)

use strict;
use warnings;
use Data::Dumper;
use CGI;

my $q = new CGI;
print $q->header('Content-Type: text/plain;');
print Dumper(\%ENV);

なんか手順が漏れてる気がするので、まちがってたら修正します

性能を測ってみたら以下の通り。


$ ab -n 300 -c 15 http://localhost:10083/test.cgi
(略)
Time taken for tests:   1.281 seconds
Complete requests:      300
Failed requests:        0
Broken pipe errors:     0
Total transferred:      856500 bytes
HTML transferred:       807600 bytes
Requests per second:    234.19 [#/sec] (mean)
Time per request:       64.05 [ms] (mean)
Time per request:       4.27 [ms] (mean, across all concurrent requests)
Transfer rate:          668.62 [Kbytes/sec] received

まあまあ早い気がします。

人気の投稿