1

FayeのサーバーとしてThinを使用しています。そのために、次のようなものを使用します。

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

Thinプロセスはによって監視されており、すべてが順調に発展しています。

ただし、これが本番構成の正しいセットアップであるかどうかはわかりません。私が知りたいのは、このセットアップ (フロントに Nginx または HAProxy がない) が本番環境でどのように実行されるかです。

4

2 に答える 2

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を使用しています。

于 2012-06-12T11:54:45.893 に答える
0

私は、redisでfayeを実行するためにthinを使用しています。確実に設定する

Faye::WebSocket.load_adapter('thin')

すべてのトラフィックは haproxy を通過します (最初のトラフィックは、すべてのトラフィックを https にリダイレクトするため、proxied という名前が付けられます)

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
    ...

http トラフィックの場合、/faye パスが含まれている場合は、同じセットのシン インスタンスに転送する nginx 経由でルーティングします。

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

于 2012-06-19T23:24:19.107 に答える