Skip to content

Example application demonstrating load balancing a meteor app using HAProxy

License

Notifications You must be signed in to change notification settings

alanning/meteor-load-balancing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

meteor-load-balancing

Example application demonstrating load balancing a meteor app using HAProxy

Setup

  1. Install HAProxy
# on OSX with homebrew
brew install haproxy
  1. Download this example
git clone https://github.com/alanning/meteor-load-balancing

Run

  1. Open 5 terminal windows

  2. From meteor-load-balancing directory:

# term1
haproxy -f haproxy.cfg

# term2
./run

# term3
./run 2

# term4
./run 3

# term5
./run 4

Open http://localhost:3000/ in some browsers.

Future work

Pull requests welcome.

Further Reading

Configuring logging (syslog)

HAProxy logs to syslog so that there is no downtime required by utils such as logrotate. On OSX, syslog is not set up to listen to network log requests so a bit of configuration is needed before you will be able to see HAProxy log messages.

To configure syslog on OSX:

  1. Backup syslogd start up file
sudo cp /System/Library/LaunchDaemons/com.apple.syslogd.plist /System/Library/LaunchDaemons/com.apple.syslogd.plist.backup
  1. Convert binary file to xml to be human readable / editable
sudo plutil -convert xml1 /System/Library/LaunchDaemons/com.apple.syslogd.plist
  1. Edit /System/Library/LaunchDaemons/com.apple.syslogd.plist and add the following snippet under the sockets node
 <key>NetworkListener</key>
 <dict>
   <key>SockServiceName</key>
   <string>syslog</string>
   <key>SockType</key>
   <string>dgram</string>
 </dict>

Should read like this now

 <key>Sockets</key>
 <dict>
    <key>AppleSystemLogger</key>
    <dict>
        <key>SockPathMode</key>
        <integer>438</integer>
        <key>SockPathName</key>
        <string>/var/run/asl_input</string>
    </dict>
    <key>BSDSystemLogger</key>
    <dict>
        <key>SockPathMode</key>
        <integer>438</integer>
        <key>SockPathName</key>
        <string>/var/run/syslog</string>
        <key>SockType</key>
        <string>dgram</string>
    </dict>
    <key>NetworkListener</key>
    <dict>
        <key>SockServiceName</key>
        <string>syslog</string>
        <key>SockType</key>
        <string>dgram</string>
    </dict>
 </dict>
  1. Save the file

  2. Convert back to binary file

sudo plutil -convert binary1 /System/Library/LaunchDaemons/com.apple.syslogd.plist
  1. Restart syslogd
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plist
  1. Add the following entry to /etc/syslog.conf
local2.*  /var/log/haproxy.log
  1. Include logging options in haproxy.cfg (already included in example haproxy.cfg)
    global
       log 127.0.0.1  local2 debug
    defaults
       mode http
       option httplog
       log global
  1. Restart HAproxy

HAProxy output will now log to /var/log/haproxy.log

An easy way to view log output on OSX is to run Console.app

About

Example application demonstrating load balancing a meteor app using HAProxy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published