Abstract
Caliper is a sub-project of Hyperledger and is a tool for testing the performance of blockchain smart contracts.
Very diverse test combinations can be set up, with results including throughput, latency, and resource usage.
Since all the tests given on the homepage are pitfalls and cannot be passed, the solution process is recorded here and a note is left.
Repository
- This article uses examples provided by the official website
https://hyperledger.github.io/caliper/v0.4.2/getting-started/#sample-networks
- Open source on Github
https://github.com/hyperledger/caliper-benchmarks
Table of contents
Chapter1
git clone [email protected]:hyperledger/caliper-benchmarks.git
You need to init it before entering the project, otherwise the following steps will go wrong.
cd caliper-benchmarks
npm init
Install caliper
and bind it to the latest version of besu. Note here that you can choose the binding version, but a series of subsequent settings must be consistent with this version.
npm install --only=prod @hyperledger/[email protected]
npx caliper bind --caliper-bind-sut besu:latest
There are two important settings files used by the Caliper administrator
. benchmarks is used to configure test parameters, and networkconfig, as the name implies, is used to connect to the blockchain.
npx caliper launch manager \
--caliper-benchconfig benchmarks/scenario/simple/config.yaml \
--caliper-networkconfig networks/besu/1node-clique/networkconfig.json \
--caliper-workspace .
Of course it will not go smoothly, an error will be reported here (2022/02/21: Execution day)
21 05:58:37.499+00:00 | main | INFO | Besu | Starting Besu version: besu/v22.1.0-RC4/linux-x86_64/openjdk-java-11
besu_clique | Invalid value for option '--rpc-ws-apis'
besu_clique |
besu_clique | To display full help:
besu_clique | besu [COMMAND] --help
The error is --rpc-ws-apis
that the value is illegal
Go to network/besu/1node-clique/docker-compose.yml and check it. It is indeed illegal.
Change the illegal lowercase parameters to uppercase.
--rpc-ws-apis admin,eth,miner,web3,net
--rpc-ws-apis ADMIN,ETH,MINER,WEB3,NET
The Docker image here seems to be wrong, so it should be changed to the one bound before.
image: hyperledger/besu:latest
Run the above administrator command again npx caliper launch manager ...
and you will see a series of Docker loaded and installed. The following besu_clique
starts
and then Create Contracts.
Container besu_clique Starting
Container besu_clique Started
2022.02.21-15:22:57.588 info [caliper] [caliper-engine] Executed start command in 65.953 seconds
2022.02.21-15:22:57.602 info [caliper] [caliper-engine] Executed "init" step in 0.014 seconds
2022.02.21-15:22:57.602 info [caliper] [ethereum-connector] Creating contracts...
2022.02.21-15:22:57.615 error [caliper] [caliper-engine] Error while performing "install" step: Error: connection not open on send()
There is still an exception here. I don’t know why. I looked back at Docker and found that there is no problem in generating blocks normally.
1 | INFO | BlockMiner | Produced #45 / 0 tx / 0 om / 0 (0.0%) gas / (0x6544b1ce8b974d297190d4fc832e0b5229762850197c94a1f0de78c26f6d0f92) in 0.007s
The port settings are also correct. . .
After searching for a long time, I couldn't find the reason, so I executed the administrator's command again and it passed. . .
I was a little speechless.
After that, the test was successfully executed and the report was output:
+----------+------+------+-----------------+-----------------+-----------------+-----------------+------------------+
| Name | Succ | Fail | Send Rate (TPS) | Max Latency (s) | Min Latency (s) | Avg Latency (s) | Throughput (TPS) |
|----------|------|------|-----------------|-----------------|-----------------|-----------------|------------------|
| open | 1000 | 0 | 50.1 | 29.13 | 1.78 | 14.35 | 20.5 |
|----------|------|------|-----------------|-----------------|-----------------|-----------------|------------------|
| query | 1000 | 0 | 100.1 | 0.01 | 0.00 | 0.00 | 100.1 |
|----------|------|------|-----------------|-----------------|-----------------|-----------------|------------------|
| transfer | 50 | 0 | 5.1 | 4.95 | 0.14 | 2.54 | 3.9 |
+----------+------+------+-----------------+-----------------+-----------------+-----------------+------------------+
A report.html file will be generated under root and can be viewed through the browser
Chapter2
Caliper is mainly divided into three parts, blockchain construction, smart contract deployment and testing, which can be split and combined at will.
No | combination | Remark |
---|---|---|
1 | Blockchain construction | Docker automatically builds it, you can build it yourself as needed |
2 | Smart contract deployment | Provide the abi.json of the contract, and Caliper will deploy the bytecode to the chain. *Note: There are requirements for abi.json here. Deploying your own smart contract will be introduced in detail in the next article. |
3 | test | Execute tests and generate reports |
Blockchain construction:
Caliper is automatically built with Docker, and is set in networks/besu/1node-clique/docker-compose.yml. Start and Start
stop are controlled in - end
in networks/besu/1node-clique/networkconfig.json .caliper
command
Smart contract deployment:
Configure all settings linked to the blockchain in networks/besu/1node-clique/networkconfig.json, mainly the url
port contracts
. You can refer to the settings here to deploy your own contracts later.
contractDeployerAddress
, contractDeployerAddressPrivateKey
, fromAddressSeed
needs to be set to the address provided by Caliper. There is no need to change it when running the Sample here. When you deploy your own contract later, you need to configure it according to your own situation.
Testing:
All test cases are configured in scenario/simple/config.yaml. You can change the sending tps, set the number of workers, etc.