Network of Nodes
Testing with a network of nodes is going to be the most beneficial way to stress your application. There are many different issues that you might come across when testing this way versus just a single node. Internal network communication between nodes could fail, there could be synchronization issues, nodes could fail to join the network, and a host of other issues may present themselves. Since a real network is going to be sharded and have many nodes in the network, it is essential to test this way before deploying your application.
Install the CLI tool with the following command:
npm i -g shardus # OR yarn add global shardus
In the root of your project, run:
You will be asked a series of questions to configure the network directory
? Choose the main server file path (dist/index.js) ? What name should be the folder to be created for the network instances ? (instances) ? How many nodes do you want to create ? (10) ? Whats the starting external port ? (the nodes will be created from starting external port to starting external port + number of nodes (9001) ? Whats the starting internal port ? (the nodes will be created from starting internal port to starting internal port + number of nodes (10001) ? Do you want to run a archive-server instance locally ? (Y/n) ? Which port do you want to run the archive-server ? (4000) ? Do you want to run a monitor server instance locally ? (Y/n) ? Which port do you want to run the monitor server ? (3000) ? Do you want to run an explorer-server instance locally ? Yes ? Which port do you want to run the explorer-server ? 4444
Unless you need some specific configuration for your network, it's usually ok to just hit
enterthrough all the questions or use the desired number of network nodes at the end of the command
shardus create 10.
Upon successful creation, you should see the following information for the number of instances you created:
Created server instance on folder <shardus-instance-9001> Created server instance on folder <shardus-instance-9002> Created server instance on folder <shardus-instance-9003> Created server instance on folder <shardus-instance-9004> Created server instance on folder <shardus-instance-9005> Created server instance on folder <shardus-instance-9006> Created server instance on folder <shardus-instance-9007> Created server instance on folder <shardus-instance-9008> Created server instance on folder <shardus-instance-9009> Created server instance on folder <shardus-instance-9010>
After a successful creation of node instances, the Shardus CLI tool will automatically start the network with the provided configurations.
When you are finished with your test, you should always stop the network and clean up the
shardus stop shardus clean rm -rf instances
When you want to restart a new network after cleaning up the old network.
Here are some quick and easy aliases for your
.zshrc file that will lessen the amount of typing overhead:
alias snc="shardus create" alias sns="shardus start" alias snst="shardus stop" alias sncl="shardus clean" alias snr="shardus stop && shardus clean && .. && rm -rf instances"