Search code examples
nginxunicornhigh-availability

Unicorn multiple machines setup


I have a good experience with Unicorn configuration with conjunction of Nginx, it works really well after optimizations and tuning procedures. But now I have got a question what is the best way to spread the load across multiple machines with Unicorns.

The question is you have 3 machines (Nginx load balancer, 2 APP servers with Unicorns), how do you manage load balancing of Unicorns with serving static assets.

Do you now any drawbacks with connection to Unicorn over TCP (timeouts, connection lost), is there any other way to upstream socket connection over the network (maybe port forwarding over SSH)? Unicorn designed to be stateless, but how do you manage the edge cases?

I don't want to serve static from balancer node, so would it be ok to setup Nginx on each of APP server and setup dumb Nginx balancer in front of them?

P.S. My current configuration is well-tested and can be found on Github, but the setup with Nginx+Unicorn on the same machine that already became a bottleneck.

UPDATE: Development is rigidly depends on the specific server configuration. Bottlenecks are going to happen not just because of developer's decisions, but also with the environment where he run it. Stackoverlow is full with highly marked Q&A related to the hard-to-know details about specific configuration. Alex who answered below works with Github I'm really appreciate to have a reply by such qualified person!


Solution

  • Don't access the Unicorns over TCP/network.

    Your setup seems just fine, you can simply add a load-balancer in front of the APP servers, but I would suggest Keepalived (LVS ftw) as load-balancer instead of Nginx.

    You can have them balance connections to the APP servers running Nginx+Unicorns over sockets.