通过caliper进行压力测试程序
第一步. 配置基本环境
安装nodejs
实战一:搭建本地链用caliper压测
第一步:搭链
安装依赖
sudo apt install -y openssl curl
cd ~ && mkdir -p fisco && cd fisco
curl -#lo https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/fisco-bcos/fisco-bcos/releases/v2.9.1/build_chain.sh && chmod u+x build_chain.sh
bash build_chain.sh -l 127.0.0.1:4 -p 30300,20200,8545
bash nodes/127.0.0.1/start_all.sh
第二步:配置网络配置文件
{
"caliper": {
"blockchain": "fisco-bcos"
},
"fisco-bcos": {
"config": {
"privatekey": "bcec428d5205abe0f0cc8a734083908d9eb8563e31f943d760786edf42ad67dd",
"account": "0x0ff8981ebc130c7874ac7093a4d0c0e3d4f36b08"
},
"network": {
"nodes": [
{
"ip": "127.0.0.1",
"rpcport": "8545",
"channelport": "20200"
},
{
"ip": "127.0.0.1",
"rpcport": "8546",
"channelport": "20201"
},
{
"ip": "127.0.0.1",
"rpcport": "8547",
"channelport": "20202"
},
{
"ip": "127.0.0.1",
"rpcport": "8548",
"channelport": "20203"
}
],
"authentication": {
"key": "/root/fisco/nodes/127.0.0.1/sdk/sdk.key",
"cert": "/root/fisco/nodes/127.0.0.1/sdk/sdk.crt",
"ca": "/root/fisco/nodes/127.0.0.1/sdk/ca.crt"
},
"groupid": 1,
"timeout": 100000
},
"smartcontracts": [
{
"id": "helloworld",
"path": "src/fisco-bcos/helloworld/helloworld.sol",
"language": "solidity",
"version": "v0"
}
]
},
"info": {
"version": "2.0.0",
"size": "4 nodes",
"distribution": "single host"
}
}
测试脚本文件介绍
测试配置文件位于./benchmarks/samples/fisco-bcos/helloworld/config.yaml
第三步,对本地四节点链进行测试
cd /home/myy/desktop/benchmarks/caliper-benchmarks
npx caliper benchmark run --caliper-workspace /home/myy/desktop/benchmarks/caliper-benchmarks --caliper-benchconfig /home/myy/desktop/benchmarks/caliper-benchmarks/benchmarks/samples/fisco-bcos/helloworld/config.yaml --caliper-networkconfig /home/myy/desktop/benchmarks/caliper-benchmarks/networks/fisco-bcos/test/fisco-bcos2.json
--caliper-workspace
:指定 caliper 的工作空间路径,通常是包含 benchmark 配置和网络配置的目录路径。--caliper-benchconfig
:指定要运行的基准测试的配置文件的路径。这个配置文件描述了性能测试的参数、交易的工作负载等。--caliper-networkconfig
:指定网络配置文件的路径。这个文件描述了要连接的区块链网络的信息,如节点地址、身份验证等。
第四步:停止节点
cd /root/fisco/nodes/127.0.0.1/stop_all.sh
通过java sdk进行压力测试
第一步:安装jdk
sudo apt install openjdk-11-jdk
java --version
第二步编译源码
./gradlew build
第三步. 配置demo
cd dist
cp -r ~/fisco/nodes/127.0.0.1/sdk/* conf
peers=["127.0.0.1:20200", "127.0.0.1:20201","127.0.0.1:20202","127.0.0.1:20203"]
第四步. 执行示例压力测试程序
注意:你的本地链需要启动
cd dist
java -cp 'conf/:lib/*:apps/*' org.fisco.bcos.sdk.demo.perf.performanceok 10000 1000 1
发表评论