1

我正在使用Thin作为Faye的服务器。为此,我使用这样的东西:

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

瘦身过程受到上帝的监督,一切都在发展中。

但是,我不确定这是否是生产配置的正确设置。我想知道的是这个设置(前面没有 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

我一直在用thin来运行faye和redis。确保设置

Faye::WebSocket.load_adapter('thin')

所有流量都通过 haproxy(第一个被命名为代理,因为我将所有流量重定向到 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
    ...

如果是 http 流量,我会通过 nginx 路由它,如果它包含 /faye 路径,它会转发到同一组瘦实例。

我不是 haproxy 专家,但这适用于 websocket 和长轮询连接。

于 2012-06-19T23:24:19.107 回答