GearmanとかNginxとか
ひさびさにFemoを弄った。
                                 サーバ周りを中心にいくつか改善
まず、以前FastCGIの環境で動かないと書いたText::VimColorをGearmanを使うようにしてみました。
                                 Text::VimColorはText::Hatena(バージョン0.16)の中で使われています
                              
#Worker(worker.pl)
                              
my $worker = Gearman::Worker->new;
$worker->job_servers(qw/127.0.0.1/);
$worker->register_function(
    vimcolor_html => sub {
        my $g = shift;
        my $arg = Storable::thaw( $g->arg );
        my %arg = map { $_ => $arg->{$_} } grep { $_ !~ /^(file|vim_command|vim_options|vim_let)$/ } keys %$arg;
        my $syntax = Text::VimColor->new(%arg);
        return $syntax->html;
    }
);
$worker->work() while 1;
                              
                                 #Text::Hatena::SuperpreNodeを上書き
                              
use Gearman::Client;
use Storable;
sub Text::Hatena::SuperpreNode::format_vimcolor {
    my $self = shift;
    my $s = shift;
    $self->{syntax_type} = $self->{syntax_type} eq '?' ?
        '' : $self->{syntax_type};
    my $client = Gearman::Client->new;
    $client->job_servers( '127.0.0.1' );
    my $result_ref = $client->do_task(
        'vimcolor_html',
        Storable::freeze( { 
            string => $s,
            filetype => $self->{syntax_type},
        } )
    );
    return unless $result_ref;
        $$result_ref;
}
                              workerとgearmandはdaemontoolsで起動してます
#gearmand起動スクリプト
                              
#!/bin/sh exec 2>&1 exec setuidgid apache /usr/bin/gearmand
                                 #worker起動スクリプト
                              
#!/bin/sh exec 2>&1 exec /path/to/Femo/script/vimcolor_worker.pl
                                 こうすると、workerの再起動が、
                              
svc -t /service/worker
で可能になるので、変更の適用がすごく楽になります
                                 万が一プロセスが落ちても、すぐに復帰してくれるのも利点です
                                 これでFastCGIでも動作ができるようになったので、Apacheのmod_perlからNginxのFastCGIへ変更しました
                                 FastCGIのプロセスもdaemontoolsで起動します
#fastcgi起動スクリプト
                              
#!/bin/sh exec 2>&1 exec /path/to/Femo/script/femo_fastcgi.pl -l 127.0.0.1:9001 -p /var/run/femo_fastcgi.pid -n 3
                                 あとはNginxの設定になります。NginxでCatalystを動かすドキュメントは本家のWikiにもあります。
FastCGIに渡す、パラメータのConfigファイル(nginx_fastcgi_params.conf)
                              
fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_param REDIRECT_STATUS 200;
                                 Nginxの設定 nginx.conf
                              
http {
    gzip             on;
    server {
        listen 80;
        server_name femo.jp;
        location / {
            fastcgi_pass 127.0.0.1:9001;
            include      /path/to/conf/nginx_fastcgi_params.conf;
        }
        location /static {
            alias /path/to/Femo/root/static;
            expires  31d;
        }
    }
}
                              
                                 全部起動して、設定完了です
                                 パフォーマンスとか全然はかってないけど、なんかモダンになった気がします
workerの危険なオプションを取り除く正規表現を間違えて3〜4時間悩んでいたのは秘密