Dockerising Caliper and Integrate with your Own Hyperledger Fabric Network- Plug & Play: Performance Benchmark Testing
Hey Everyone,
I got a lot of request for integrating caliper with own Hyperledger Fabric Network. So I decided to containerize caliper so that everyone can plug and play with their own existing network and test performance benchmark of the network. There would be minimal changes in the containerized caliper.
Again, here I am assuming that you have your own network up and running, In case you don't have your own network, Here first we will create our own fabric network.
I have created a Youtube video as well, it has a detailed explanation, you can check both articles and videos. Including link here.
PART 1
PART 2:
STEP 1: Running our OWN network(If you have your own network up already, you can skip this step)
Clone Basic Network Repo form HERE.
Once you cloned above the repo, just go to the home folder of the repo (BasicNetwork_1.4.4).
Network Structure:
1) 2 ORGS having 2 Peers each(One Endorsing Peer for each Org)
2) 3 RAFT Orderer
3) 4 Cuch DB
4) 2 Certificate Authority
Here I am using fabric 1.4.4 for creating the network. I hope you have already prerequisites installed on your machine with images 1.4.4. If you want to create a network with other versions, please feel free to make changes accordingly in the repo, especially in a docker-compose file for an image version.
Go to cd artifacts/channel/ folder in repo
Run following script
1) ./createArtifacts.shIt creates all necessary cryptomaterials and channel artifacts for our network. you can see all cryptomaterials in channel folder like below image
a. crypto-config
b. genesis.block
c. mychannel.tx
d. Org1MSPanchors.tx
e) Orge2MSPanchors.tx
Come back to the artifacts folder.
2) Running all ContainersBefore running containers, go to dockerc-compose.yaml file and give the correct private file name for both certificate authority, in my case it is priv_sk . As per cryptogen version private key name could be different format like priv_sk or long_string_sk.Once you are done with changes with both Certificate authority(First two services) run below commanddocker-compose up -d This will run all necessary services for our network. you can see all containers using docker ps
3) Create and Join Channel
Run below command
./createChannel.shThis command will create channel and join all peer to channelInside channel-artifacts folder you could see mychannel.block.
PLease make sure that all commands defined in scripts run successfully
4) Install chaincode on Endorsing Peer and instantiate.Run below command
./deployChaincode.shThis command will install chaincode on endorsing peer and instantiate. Run "docker ps" and You can see additional chincode container.
Our Network is up and running, There would be 15 total containers as below.
STEP 2: Run Caliper in Container with correct Configurations
I have created one repo, Please clone it from HERE
Once you clone repo successfully, got to the home folder. It's having very precise folder structure as below.
The most Important file is the docker-compose file. Lets Explorer it.
There is one service defined in docker-compose file ie caliper. Inside service, we have provided three important environment files and mounted one volume.
- CALIPER_BIND_SUT
- CALIPER_BENCHCONFIG
- CALIPER_NETWORKCONFIG
- Mounted Volume
STEP 1: Please bind the correct SUT(System Under Test) — Fabric and your network version like “fabric:1.4.4” or “fabric:1.4.6”(As per your network version). When I wrote this article, fabric 2.x was not supported.
STEP 2: BenchConfig
In Caliper benchmark repo I have created my own folder for all config files as mentioned in the environment folder.
It's related to the client and we defined configuration like the number of rounds, number of transactions, arguments, and the callback function.
We have one callback function in same folder benchmarks/scenario/simple/pavan/open.js inside caliper-benchmark repo(This repo is Submodule in our main repo)
Open.js
This file has the logic for our transaction creation. There are two main functions, run and init, Init will execute for one time and run will execute for whatever number of transactions we have mentioned in the config.yaml file. This is for one Worker(Client), which is defined in config.yaml. If we define multiple clients(Workers), this will get divided accordingly.
In our own fabric network, I have used Fabcar as the smart contract. You could see the logic for creating a car asset in generateWorkload() method.
If we want to trigger multiple assets in a single transaction, we can define in open.js file or pass as argument form config.yaml
In the run function, I am creating cars with given parameters.
Note: All the logic written here will get changed as per your own smart contract. Please make sure that you have done the necessary changes in the open.js file.
STEP 3: Network Config
Location of the file inside caliper Repo:
Path: networks/fabric/pavan/network-config.yaml
In this file, please define the correct configuration. Inside this folder (networks/fabric/pavan/), just copy and pest crypto-config folder of your own running fabric network(Not necessary to copy all files, but some of the files we require an in-network config file.). As per your own running network please add/remove orgs, peers, orderers, ca configuration, and provide the correct path as given. While providing the private key name in the path, please make sure to give correct as mentioned in your crypto-config folder. Mention the correct port as per your network.
We have to copy our chain code and put inside the below folder: fabric/pavan/go
which is available inside the src folder on the home location of the repo.
STEP 4: Mount Caliper-benchmark official repo
That's it, we have done all necessary changes with the repo. Let's start a caliper container and benchmark the performance of the fabric network.
Go to the home location of the repo. you can see docker-compose.YAML file there.
Run below command
docker-compose up -d
You can see a Caliper container get created. Once caliper container is running(you can see running container: run this command- docker ps
), Monitor the log of the container by the following command
docker logs caliper -f
You can see caliper container logs in the terminal, it takes time as per the configuration of the machine, network configuration, number of transaction, and number of rounds.
Once benchmarking of the network done, there would be a report.html file on the home location of the repo. Just open in the browser and Enjoy!
Sample Report File (Save as HTML and open in any browser). The result is not so good for me as my resource configuration is very low, In your case, it could be one of the best.
There are the number of parameters that affect the performance of the Hyperledger Fabric Network. You can play around these parameters and fine-tune the network for best performance. Let's see the result. I will summerise all of your results and make one Performance Report for the community.
- Number of endorsing peers
- Number of channels
- Number of endorsements (endorsement policy)
- Ordering service configuration (block size and batch time)
- Number of organizations
- Ledger database used
- The complexity of chain code/smart contract execution
- Size of transactions size of transactions
- Use of mutual TLS for all network traffic
- Number of vCPUs
- Memory allocation
- Disk type and speed
- Network speed
- Multiple datacenter deployments
- CPU speed
- Crypto acceleration
You can define any number of rounds in config.yaml
file like
1) Create Car asset
2) Query Car asset
3) Transfer Car asset
Here I am talking about fabcar smart contract, you can do necessary changes in your own smart contract.
Play around with different rate control(Fixed and variable) to achieve the best performance result.
In case if you are facing any issue, please let me know, I would love to help you. You can get in touch with me on linked in or Instagram.
https://www.instagram.com/pavanadhavofficial/
https://www.linkedin.com/in/pavan-adhav/
Email: adhavpavan@gmail.com
Please share your TPS and Throughput with me on Instagram, let’s see how we can fine-tune fabric network for best performance.
If you feel this article is useful, You can buy a coffee for me on https://www.paypal.me/PAVANADHAV
https://ko-fi.com/adhavpavan
https://www.patreon.com/adhavpavan
Thank you.
References
- https://github.com/hyperledger/blockchain-explorer
- https://hyperledger-fabric.readthedocs.io/en/release-1.4/prereqs.html
- https://docs.docker.com/compose/