-
webサーバ Thin を使ってみる 2008-01-07 23:07:49
Mongrelより速いというウワサのThinというwebサーバを会社の同僚の方に教えてもらいました。実際に計測してみるとmongrelより速いそうです。mongrelの開発者がグレてしまったので、Thinを使ってみるのもいいかもしれません。ちょっと試してみました。
まずはインストール。
sudo gem install thin
あとはRAILS_ROOTに移動して、
thin start
でOKです。超簡単(デフォルトのポート番号は3000です)。もちろん、RAILS_ENVやポート番号も指定できるしデーモンとして起動することもできます。
thin -p4000 -e production -d
みたいな感じ。デーモンとして起動したときは
thin stop
で停止できます。
いちいち手で入力するのが面倒なので、複数プロセスで起動するthin_clusterを作ってみました。
#!/usr/bin/ruby require 'yaml' CONFIG_FILE = "config/thin_cluster.yml" def error puts "thin_cluster config|start|stop [options]" exit end error if ARGV.size < 1 mode = ARGV.shift case mode when "config" config = {:env => "development", :port => 3000, :servers => 1} if i = ARGV.index("-e") config[:env] = ARGV[i + 1] end if i = ARGV.index("-p") config[:port] = ARGV[i + 1].to_i end if i = ARGV.index("-N") config[:servers] = ARGV[i + 1].to_i end YAML.dump(config, File.open(CONFIG_FILE, "w")) when "start" config = YAML.load_file(CONFIG_FILE) config[:servers].times do |i| `thin -e #{config[:env]} -p #{config[:port] + i} -P "tmp/pids/thin.#{config[:port] + i}.pid" -d start` end when "stop" config = YAML.load_file(CONFIG_FILE) config[:servers].times do |i| `thin -P "tmp/pids/thin.#{config[:port] + i}.pid" stop` end else error endthinコマンドをそのまま呼んでるだけの超手抜きですが、まあ自分が使うだけだしこれでいいや。さっそく、kaeruspoonとmilookとかえるイメージをthin_clusterで動かしてみます。しばらく様子を見よう。
追記
続きが「Thinサーバーをまた使ってみる」にあります。

コメント(
リンク元(202)