2012-05-09 10 views
1

FayeのサーバーとしてThinを使用しています。生産の薄いベストプラクティス

require 'faye' 
bayeux = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25) 
bayeux.listen(9292) 

シンプロセスがGodによって監視され、すべての開発でもある。これを行うには、私はこのようなものを使用します。

しかし、これが運用環境設定に適しているかどうかはわかりません。私が知りたいのは、プロダクション環境でこの設定(NginxやHAProxyが前面にない)がどのように実行されるのかです。

答えて

1

これは私の神の設定です。

#Faye 
ports = [9292, 9293, 9294, 9295] 
ports.each_with_index do |port, id| 
    God.watch do |w| 
    w.dir  = "#{rails_root}" 
    w.name  = "faye-#{port}" 
    w.group = "faye" 
    w.interval = 30.seconds 
    w.start = "thin start -R #{rails_root}/faye.ru -e production -p #{port} -P #{rails_root}tmp/pids/faye-#{port}.pid" 
    w.stop  = "thin stop -P #{rails_root}tmp/pids/faye-#{port}.pid" 
    w.log  = "#{rails_root}/log/god_node.log" 

    #w.uid = 'server' 
    #w.gid = 'server' 

    # restart if memory usage is > 500mb 
    w.transition(:up, :restart) do |on| 
     on.condition(:memory_usage) do |c| 
     c.above = 500.megabytes 
     c.times = 2 
     end 
    end 

    # determine the state on startup 
    w.transition(:init, { true => :up, false => :start }) do |on| 
     on.condition(:process_running) do |c| 
     c.running = true 
     end 
    end 

    # determine when process has finished starting 
    w.transition([:start, :restart], :up) do |on| 
     on.condition(:process_running) do |c| 
     c.running = true 
     c.interval = 10.seconds 
     end 

     # failsafe 
     on.condition(:tries) do |c| 
     c.times = 5 
     c.transition = :start 
     c.interval = 10.seconds 
     end 
    end 

    # start if process is not running 
    w.transition(:up, :start) do |on| 
     on.condition(:process_running) do |c| 
     c.running = false 
     end 
    end 
    end 
end 

と私はロードバランシングにnginxを使用しています。

+0

助けてくれてありがとうルイスですが、これは実際にNginxの使い方とベストプラクティスによるThinのロードバランシングの問題には答えていません。 – Khash

+0

私は知っています。ちょうど私の2セント。どういうわけか役立つかもしれない、と思う。ベストプラクティスを確認するには、「faye-users」Googleグループ –

0

私はredayでfayeを実行するためにシンを使用しています。作るすべてのトラフィックが(最初のものは、私はhttpsにすべてのトラフィックをリダイレクトするようプロキシ命名された)

frontend proxied 
    bind 127.0.0.1:81 accept-proxy 
    timeout client 86400000 
    default_backend nginx_backend 
    acl is_websocket hdr(Upgrade) -i WebSocket 
    acl is_websocket hdr_beg(Host) -i ws 
    use_backend socket_backend if is_websocket 


backend nginx_backend 
    balance roundrobin 
    option forwardfor #except 127.0.0.1 # This sets X-Forwarded-For 
    timeout server 30000 
    timeout connect 4000 
    server nginx1 localhost:8081 weight 1 maxconn 20000 check 

backend socket_backend 
    balance roundrobin 
    option forwardfor except 127.0.0.1 # This sets X-Forwarded-For 
    timeout queue 5000 
    timeout server 86400000 
    timeout connect 86400000 
    server socket1 localhost:3100 weight 1 maxconn 20000 check 
    server socket2 localhost:3101 weight 1 maxconn 20000 check 
    server socket3 localhost:3102 weight 1 maxconn 20000 check 
    server socket4 localhost:3103 weight 1 maxconn 20000 check 
    ... 

それが転送nginxの経由でHTTPトラフィックIルートそれがある場合haproxyを通過

Faye::WebSocket.load_adapter('thin') 

を設定してください/ fayeパスが含まれている場合は、シン・インスタンスの同じセットに追加します。

私はhaproxyの専門家ではありませんが、これはwebsocketと長い投票接続で機能しています。