Rails

Railsで使える高速サーバThin

2008/03/09

thin.png

EbbなどThinよりも高速なサーバもあるようですが、gemのみでインストールできて、Mongrelよりも早いようなので試してみました。以下、メモ。

試したのは mod_proxy(Apache2.0)+ Thin です。mod_proxy の設定はこんな感じです。

Thinのconfigファイルを作る

Thin はオプションをいろいろとつけて起動させますが、Mongrel 同様、これを設定ファイルに記述しておくこともできます。

thin config -C config/thin.yml -p3333 -d

これでconfig/thin.yml にオプションが書き込まれました。指定したのは、ポート番号3333でデーモンで起動する、ということだけです。ymlをのぞいてみると、port:3333、daemonize: trueとなり、それ以外はデフォルトの値が使用されています。

pid: tmp/pids/thin.pid
log: log/thin.log
max_conns: 1024
port: 3333
timeout: 30
chdir: /var/www/rails/test
environment: development
max_persistent_conns: 512
address: 0.0.0.0
daemonize: true

configファイルを使って起動

上で設定したオプションで起動します。

thin start -C config/thin.yml

停止

PID ファイル(プロセスIDのみ書かれたファイル)が、デフォルトの位置(tmp/pids/thin.pid)にあれば、下記のように停止します。

thin stop

別の場所にあるのであれば、下記のように PID ファイルを指定して、停止させます。

thin stop -P tmp/pids/thin_hogehoge.pid

Clusterとして起動する

クラスターとして起動させるには、ここを参照して下さい。

またポートで振り分けるのではなく、ソケットでわけたい場合も下記のようにすることで可能になります。

thin start --server 3 --socket /tmp/thin.sock

このようにすると、/tmp/thin.0.sock、/tmp/thin.1.sock、/tmp/thin.2.sockが生成されるので、バランサーでこのファイルを指定します。ソケット通信の方が早いようですね。


related posts


tags

, ,


have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

:

:


« Apache + Mongrel / Thin で ベーシック認証
» 池田亮司 datamatics [ver.2.0] へ