This repository contains source code of an implementation of the bully algorithm written in Go and a small browser visualization tool.
This has been made for learning purposes about distributed algorithms, Bully algorithm being the simplest leader election algorithm to implement.
Finally, I feel like implementing an algorithm myself helps me to understands it better and I thought it could be interesting to someone else.
The Bully algorithm is one of the simplest algorithm made to design a coordinator among a set of machines.
First, go get this repository:
go get -d github.com/timtosi/bully-algorithm
❗ If you don't have Docker and Docker Compose installed, you still can execute this program by compiling the binaries.
This program comes with an already configured Docker Compose file launching five nodes and the browser based user interface.
You can use the run
target in the provided Makefile to use it easily:
You can access the visualization through your browser at localhost:8080
.
If you want to test the cluster behaviour, you can stop and resume some of the
nodes with docker commands.
💡 If you want to update the number of node or change some IDs you will have to update the configuration file and the Docker Compose file accordingly.
First compiles and launch the visualization server:
cd $GOPATH/src/github.com/timtosi/bully-algorithm/cmd/data-viz
go build && ./data-viz
Then launch at least two nodes with specifying their ID in argument:
cd $GOPATH/src/github.com/timtosi/bully-algorithm/cmd/bully
go build && ./bully 0
💡 IDs should by default be comprised between 0 to 4 but you should be able to update peer address default configuration easily.
You can access the visualization through your browser at localhost:8080
.
None so far 🙌
Every file provided here is available under the MIT License.
If you encouter any issue by using what is provided here, please let me know ! Help me to improve by sending your thoughts to timothee.tosi@gmail.com !