This project is an attempt to build the proof of concept of node.js auto discoverable cluster. It's possible, that nodes of the cluster could be located in the different networks.
In detail, the project is described in the articles which are linked below:
- Node.js clustered app with autodiscovery. Part 1 - gathering the blocks
- Node.js clustered app with autodiscovery. Part 2 - the demo app
Video: Running the app
Next technologies are used:
- Vagrant (for virtualization, at least version 1.7.4)
- etcd (to store the registry of the active nodes)
- node-discover (auto discovery framework)
To run the app the next should be done
- Vagrant >= 1.7.4 should be installed
- Assuming you are going to setup the project to the folder
- Checking out the git repository
cd /Users/user/ mkdir etcd-test cd etcd-test git clone https://github.com/PavelPolyakov/etcd-test.git .
- Preparing the etcd machine
cd /Users/user/etcd-test/ cd etcd-vagrant vagrant up ./IP.sh # write down the IP and port of the etcd server # let's assume that it is 172.28.128.22:4001
cd /Users/user/etcd-test/ cd node-app-vagrant cd config cp default.js.sample default.js vi default.js # here we need to put the actiaul etcd server IP:port to the etcd section of the config, instead of the example one # let's assume, that the we have adjusted the config cd .. vagrant up
During the machine instantiating, Vagrant would prepare three servers - A,B,C. Each server is able to run the node-app node, all together they should build up a cluster. 6. After some time, the machines would be instantiated. It's time to run the application. Let's open three terminals - one per app.
vagrant ssh A cd node-app npm run app
vagrant ssh B cd node-app npm run app
vagrant ssh C cd node-app npm run app
In case we did everyhing right before, there is a good chance to see that three of our nodes are up. One of the is master. Master sends the tasks to the worker nodes, workers are performing the calculations and returning the results to the master.