Hyperledger caliper使用入门
程序员文章站
2022-05-13 19:58:57
...
目录
环境
- os: centos7.6
- node-gyp,python2,make,g++和git
- node.js v8.9.0
- docker,docker-compose
1. 介绍
Caliper是一个区块链性能测试框架,允许用户使用自定义用例测试不同的区块链解决方案,并获得一组性能测试结果。
支持的区块链解决方法:
- Hyperledger Besu
- Hyperledger Burrow
- Ethereum
- Hyperledger Fabric
- FISCO BCOS
- Hyperledger Iroha
- Hyperledger Sawtooth
支持的性能指标
- Transaction/read throughput
- Transaction/read latency (minimum, maximum, average, percentile)
- Resource consumption (CPU, Memory, Network IO, …)
2. 下载caliper-benchmarks
包含区块链性能基准框架Caliper使用示例(fabric、以太坊、burrow等),主仓库参考caliper。
git clone https://github.com/hyperledger/caliper-benchmarks.git
cd caliper-benchmarks
3. 本地安装caliper-cli
注意:强烈建议您为项目安装Caliper。将项目依赖项保持在本地,可以更轻松地设置多个Caliper项目。每次运行新的基准测试之前,全局依赖项都需要重新绑定(以确保正确的全局依赖项)。
3.1 初始化项目
npm init -y
执行完后,会在当前目录生成package.json文件
3.2 安装caliper-cli
npm install --only=prod @hyperledger/[email protected]
执行完后,会将依赖下载到当前目录下的node_modules文件下下
3.3 查看帮助
npx caliper --help
caliper <命令>
命令:
caliper bind [options] Bind Caliper to a specific SUT and its SDK version
caliper launch <subcommand> Launch a Caliper process either in a master or worker role.
caliper completion generate completion script
选项:
--help, -h Show usage information [布尔]
--version Show version information [布尔]
示例:
caliper bind
caliper launch master
caliper launch worker
For more information on Hyperledger Caliper: https://hyperledger.github.io/caliper/
4. 运行测试用例
这里测试burrow(目前支持最新的版本为v0.23.1)
npx caliper bind --caliper-bind-sut burrow:0.23.0
npx caliper launch master \
--caliper-workspace . \
--caliper-benchconfig benchmarks/scenario/simple/config.yaml\
--caliper-networkconfig networks/burrow/simple/burrow.json
burrow.json,需要修改一下contract默认路径
{
"caliper" : {
"blockchain": "burrow",
"command" : {
"start": "docker-compose -f networks/burrow/simple/docker-compose.yml up -d",
"end" : "docker-compose -f networks/burrow/simple/docker-compose.yml down"
}
},
"burrow": {
"network": {
"validator": {
"host": "localhost",
"port": "20002",
"address": "networks/burrow/simple/chain/keys/names/Full_0"
}
}
},
"contract": { "path": "src/burrow/scenario/simple/simple.bin" },
"info" : {
"Version": "develop",
"Size": "2 Peers",
"Distribution": "Single Host"
}
}
如果不出意外,会在控制台打印性能测试结果,也会在当前目录生成report.html文件。
+----------+------+------+-----------------+-----------------+-----------------+-----------------+------------------+
| Name | Succ | Fail | Send Rate (TPS) | Max Latency (s) | Min Latency (s) | Avg Latency (s) | Throughput (TPS) |
|----------|------|------|-----------------|-----------------|-----------------|-----------------|------------------|
| open | 100 | 0 | 50.5 | 1.78 | 0.22 | 1.25 | 33.2 |
|----------|------|------|-----------------|-----------------|-----------------|-----------------|------------------|
| query | 100 | 0 | 101.2 | 0.00 | 0.00 | 0.00 | 101.1 |
|----------|------|------|-----------------|-----------------|-----------------|-----------------|------------------|
| transfer | 0 | 100 | 50.5 | 0.00 | 100000.00 | NaN | 0.0 |
+----------+------+------+-----------------+-----------------+-----------------+-----------------+------------------+
参考
https://hyperledger.github.io/caliper/v0.3/installing-caliper/