Dabase setup is necessary to run this project as this project requires a MongoDb server to be up and running in the local system. Setting up Mongo using docker is convinient and highly recommended.
Following are the steps to setup database using docker:
-
Pull the official mongo docker image from docker hub using
docker pull mongo
-
Make sure that any old mongo container is removed if not then stop any running container using
docker stop <container_id>
container_id can be fetched usingdocker ps
. Remove the stopped container usingdocker rm <container_id>
-
Now run
docker run -d -p 27017:27017 --name mongo_container mongo
to start the docker container on port 27017.
Database can also be setup in one go using database_setup.sh file provided. Just make sure that any previous container is stopped and removed then run sudo bash setup_database.sh
.
docker run -d -p 27017:27017 --name mongo_container mongo
-
It is advisable to create and activate a virtualenv before starting the project. However it is not a requirement to run the project.
-
The current project has three different flavours: a. mutlitreaders without cache: src/multiple_traders b. mutlitreaders with cache: src/cache_sync c. two treaders with fault tolerance: src/two_traders To run any of the flavours cd into the appropriate directory and follow steps 3 and 4
-
The application can be started by running a single bash script run.sh inside src folder once database setup is done.
-
Make sure that you current directory is src and then run
bash run.sh host_name <number_of_peers> <number_of_traders>
-
Hostname is a mandatory parameter and needs to be passed as a command line argument for the program to start.
-
Number of peers is optional paramter if passed the network will generate a network with equivalent number of peers otherwise it will default to six peer network based on the default config provided in config_file.
-
A sample run command might look like
bash run.sh localhost 10 3
-
In first case a 10 peer network will be created whereas in the second a network of 6 peers will be created.
-
The output of the program after running the network for a few minutes is present in
src/cache_sync/tmp/output/trader_i.txt
for traders andsrc/cache_sync/tmp/output/database.txt
for database
We have used matplotlib to show a graphical representation of the network. Plotting of graph might not work iff a GUI backend is not present. This issue can be resolved in two ways.
-
pass show_bazar argument as false when calling create_bazar function from main. This will prevent graph_generator to be invoked and hence resolving the error. However in this way the graphical representation of the network won't pe drawn.
-
Another way is to install a GUI-backend for matplotlib ````python
sudo apt-get install python3-tk````