简体   繁体   English

Rails 4.2使用nginx redis和sidekiq进行负载均衡

[英]Rails 4.2 load balancing with nginx redis and sidekiq

Hi I just launched a rails 4 application which uses nginx as load balancer with thin serving rails on 2 ports. 嗨,我刚刚推出了一个rails 4应用程序,该应用程序使用nginx作为负载均衡器,在2个端口上使用瘦服务轨道。 Additionally I use redis as cache which is also getting used by sidekiq. 另外我使用redis作为缓存,也被sidekiq使用。

I was wondering how can I scale up using another machine in order to run two more rails applications there. 我想知道如何使用另一台机器进行扩展,以便在那里再运行两个rails应用程序。 My idea is just running two more rails applications on another machine but the headache comes with redis since sidekiq is making heavy use of it. 我的想法是在另一台机器上运行另外两个rails应用程序,但由于sidekiq正在大量使用它,因此头痛带来了redis。 My first idea was just to have another redis slave which is just read only on the second machine . 我的第一个想法就是拥有另一个redis slave,它只能在第二台机器上读取。 But this might be error prone since I have a lot of writes into redis in order to check a worker queue. 但是这可能容易出错,因为为了检查工作队列,我有很多写入redis的内容。

The following scenario kind of confuses me. 以下场景让我感到困惑。 The web app makes a request and triggers sidekiq which performs a long running action, it continuously updates the status in redis. Web应用程序发出请求并触发执行长时间运行的sidekiq,它会不断更新redis中的状态。 The web client polls the app every second in order to get the status. Web客户端每秒轮询应用程序以获取状态。 Now it could be possible that the request gets redirected to the second machine with the redis slave which is not yet updated. 现在,有可能将请求重定向到第二台机器,而redis slave尚未更新。 So I was wondering how would be the best setup, just using one redis instance taking into account latency or run a redis slave? 所以我想知道如何最好的设置,只使用一个redis实例考虑延迟或运行redis slave?

You have two machines: 你有两台机器:

  1. MachineA running thin and sidekiq. MachineA运行瘦和sidekiq。
  2. MachineB running thin and sidekiq. MachineB运行瘦和sidekiq。

Now you install redis on MachineA and point Sidekiq to MachineA for Redis. 现在,您在MachineA上安装redis,并将Sidekiq指向MachineA for Redis。 Both Sidekiqs will talk to Redis on MachineA. Sidekiqs都会在MachineA上与Redis交谈。 See Using Redis for more detail. 有关详细信息,请参阅使用Redis

Side note: A redis slave is useful for read-only debugging but isn't useful for scaling Sidekiq. 附注:redis slave对于只读调试很有用,但对于缩放Sidekiq没有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM