Local Load Balancing
You can mimic the end-user’s UI experience accurately enough by running application code locally, but what about the backend? Once your code is deployed to production, requests will be divided between dozens of servers. If there is variation in the code paths running on each server (like during a feature rollout, for example), it is useful to determine beforehand if there are any dangerous conflicts. Enter local load-balancing.
NGiNX is load balancing software that distributes requests across multiple servers, and it’s easy to get running quickly.
You can download and compile from source at NGiNX.org, or use
brew install nginx on MacOS-X.
1 2 3 4 5 6 7 8 9 10 11
Start the server with the command
Your NGiNX installation added a config file:
/usr/local/etc/nginx/nginx.conf. It is mostly commented configuration examples, so you can simply replace the current
server configuration block with this:
1 2 3 4 5 6 7 8 9 10 11 12
Reload your NGiNX server with
nginx -s reload, and hit localhost:8080 to ensure you have configured it correctly.
Start your servers
NGiNX is configured and listening on ports 3000 and 3030. Now we just have to connect some servers!
bundle exec rails server -p 3030
bundle exec rails server -p 3000 --pid tmp/pids/server2.pid
Pro-tip: The Rails server stores its process id in a temporary file (
/tmp/pids/server.pid), and will complain if you start another server unless you specify a new temporary pid file.
Check your progress by hitting localhost:8080:
Checkout the docs for more examples of nginx configuration.