EC2のサーバ上でruby-1.8.x系で動作しているpassenger(aka mod_rails)
と平行して、ruby-1.9.1を動かす環境を用意するために色々と試行錯誤を繰り返していたのですが、ひとまず良さそうな構成に落ち着いたのでメモしておきます。

構成

入り口から順に並べるとこんな感じです。

  • apache2 (:80)
  • mod_proxy_balancer (:80 -> :4000)
  • swiftiply (:4000 <- :30000)
  • merb cluster with SwiftipliedMongrel adapter (:30000)

apache2はpassengerを使っているので外せないとして、
ruby-1.9.1で動かすサービスはmod_proxy_balancerを使う事にしました。
最初はバックエンドに直接merb clusterを当てていたのですが、
現状のmerb clusterにはgraceful reloadする機能が無いようだったので、
間になにか挟む事にしました。

そこで、以前から目を付けていた
Swiftiply
を試す事にしました。
Swiftiplyはとても面白い設計のウェブサーバで、そのへんは
rakutoさんの記事
[Rails] Swiftiplyのアーキテクチャとベンチマーク
を読むのがわかりやすいでしょう。

merbはbuilt-inでSwiftiply用のアダプター(SwiftipliedMongrel adapter)を備えているので、Swiftiplyを起動する設定をおこなえば、使うのはわりと簡単です。

しかし、例によってswiftiplyが依存しているeventmachineがruby-1.9.1
でインストール出来なかったので、原因を調査。
単純にテストの実行だけがうまく動いてないようだったので、テスト無しでインストールしました。

あとは、swiftiplyの起動スクリプトを用意。

/etc/init.d/swiftiply

ruby>>
#!/usr/bin/env ruby

PID = "/var/run/swiftiply.pid"

case ARGV[0]
when 'start'
if File.exist?(PID)
puts "swiftiply is already started."
exit 1
end
print "Starting swiftiply: "
pid = fork do
Process.setsid
Process.exec "swiftiply", "-c", "/etc/swiftiply.yml"
end
begin
open(PID, "w"){|file| file.write pid}
puts "done"
rescue Exception => e
puts e.message
Process.kill 9, pid
end
when 'stop'
print "Stopping swiftiply: "
begin
pid = open(PID).read.to_i
File.unlink PID
Process.kill 9, pid
puts "done"
rescue Exception => e
puts e.message
end
when 'restart'
system $0, 'stop'
system $0, 'start'
else
puts "usage: {start|stop|restart}"
end
<<--

アプリケーションの起動、停止は以下のようにおこないます。

pre>>
cd #{current_path}; #{merb} -K all
cd #{current_path}; #{merb} -e production -a swift -c 1 -p 30000
<<--

これで動きますが、プロセスが死んだりすると不安なので、
monitを使って死活管理をおこなうようにします。

/etc/monit/monitrc

pre>>
check process swiftiply
with pidfile /var/run/swiftiply.pid
group root
start program = "/etc/init.d/swiftiply start"
stop program = "/etc/init.d/swiftiply stop"
if failed port 4000 then restart
if 5 restarts within 5 cycles then timeout

check process merbist
with pidfile /mnt/app/merbist/current/log/merb.30000.pid
group root
start program = "/mnt/app/merbist/shared/script/start"
as uid app and gid app
stop program = "/mnt/app/merbist/shared/script/stop"
as uid app and gid app
if failed port 30000 then restart
if 5 restarts within 5 cycles then timeout
depends on swiftiply
<<--

以上で完了。

現在、http://merbi.st/ は上記の設定で動いています。

See Aslo

追記

しばらく運用してみたのですが、プロセスが数時間に一回ぐらいのペースで落ちる問題があったので、Swiftiplyの代わりにPoundを使う構成に変えました。
Swiftiplyは次のバージョン0.7.0から、クラスタリングのサポートが強化されるようなので、それまで待ってみた方が良いかもしれないですね。

posted by genki genki on Fri 20 Feb 2009 at 16:05 with 0 comments
Contents rssrss
光ファイバーを二次元振動させて走査するAR用ディスプレイ
因果の取り違え
Swift2's defer for CoffeeScript
mongodb-3.0からcreateIndexのdropDupsが無くなったらしい
mongodb-3.0以降のWiredTigerの設定を動的に変更する方法
一般楕円の高速生成アルゴリズムへの道標
farro mantecatoのレシピ
Droonga関連の記事のまとめ
RuntimeErrorの特定のメッセージに限定してrescueする方法
jQueryでscriptタグを実行せずにappendする
Tags
coffeescriptdefergroongajsmemonodenodejs
Comments rssrss
http://mkbfab.com/bbs/board.php?bo_table=31&wr_id=93169 http://mkbfab.com/bbs/board.php?bo_table=31&wr_id=93169: Kaizenaire.сom stands out іn supplying promotions ... 05/25 03:10
https://blanksnowboards.com/quickwin-ios-win-big-now-easy-app-download/ https://blanksnowboards.com/quickwin-ios-win-big-now-easy-app-download/: Good read. 05/24 21:53
https://www.thegameroom.org/de/online-casinos/eu-lizenz/ https://www.thegameroom.org/de/online-casinos/eu-lizenz/: Транслируйте контент для взрослых безопасно, выбир... 05/24 21:49
http://pasarinko.zeroweb.kr/bbs/board.php?bo_table=notice&wr_id=10087836 http://pasarinko.zeroweb.kr/bbs/board.php?bo_table=notice&wr_id=10087836: Uncover Singapore'ѕ leading deals ɑt Kaizenaire.ϲo... 05/24 19:51
https://4bedroomvillaforsaleindubai.org https://4bedroomvillaforsaleindubai.org: We Advise You Let out Apartments In Dubai With all... 05/24 18:56
https://xn--d1arpf.xn--p1ai/community/profile/tiaraahotels/ https://xn--d1arpf.xn--p1ai/community/profile/tiaraahotels/: Very well written article. 05/24 18:55
https://www.thegameroom.org/backgammon-spelregels/ https://www.thegameroom.org/backgammon-spelregels/: Контент для взрослых доступен через надежные и про... 05/24 18:48
https://www.imprentaconcepcion.cl/2026/05/23/vegasino-promo-code-offers-big-wins-now/ https://www.imprentaconcepcion.cl/2026/05/23/vegasino-promo-code-offers-big-wins-now/: Thanks for the post. 05/24 18:17
Services from s21g
YOMU Web小説リーダー
小説投稿サイトの公式ページを開き、WebView表示と読み上げ向け表示を切り替えて、移動中や作業中にもWeb小説の続きを聴きやすくするiPhoneアプリです。
補助探
公開されている補助金・助成金情報を集約し、条件に合う制度を探しやすくするサービスです。
jotter.me
個人開発者のためのホスティング一体型ノートサービス
ハンドミラー
iPhone向けの手鏡アプリ
ツイプロ(twpro)
Twitterプロフィールの高速検索エンジン