• ブログ
  • Photoshare
  • キーワード
  • ブックマーク
  • ふぉとす
  • 写真
  • ログイン

kaeruspoon

« 愚か者死すべし: 本: 原 リョウ | mongrelに戻しました »
  • webサーバ Thin を使ってみる 2008-01-07 23:07:49 Append 330

     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
    end
    

    thinコマンドをそのまま呼んでるだけの超手抜きですが、まあ自分が使うだけだしこれでいいや。さっそく、kaeruspoonとmilookとかえるイメージをthin_clusterで動かしてみます。しばらく様子を見よう。

    追記
    続きが「Thinサーバーをまた使ってみる」にあります。

    Commentコメント(3) Pageリンク元(476)
« 愚か者死すべし: 本: 原 リョウ | mongrelに戻しました »

プロフィール

おおいしつかさ

過去の記事

2006年
12月
2007年
1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月
2008年
1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月
2009年
1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月
2010年
1月 2月 3月

キーワード一覧

ActionScript Ajax AmazonResources Erlang git github iPhone javascript Javascript Kaerukeyword kaeruspoon Mac merb milook MiyazakiResistance NSR Objective-C perl Perl Rails Ruby Ruby on Rails RubyKaigi speedpetal subversion Thin Thinkpad tokyobike TRPG twitter ubuntu Ubuntu VAIO VAIO typeZ Waves WordScoop Xen ぐりぐり しろさん カンタロー スノボー ドトール ドライブ バイク プログラミング ユルさん 執筆 宮崎 日本酒 模型 猫 町田 真中洋嗣 自転車
Baner