1.安装nodejs,
-
使用nvm或者系统自带的包管理器进行安装(apt或yum)
-
nodejs版本 => 8
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash 或 wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash 执行 export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # 添加环境变量
2.部署Docker
-
docker 版本 >= 18.06.01
-
安装指南:
执行
apt install docker.io 或 yum install docker
3.部署Caliper
- 新建工作目录
mkdir benchmarks && cd benchmarks-
初始化npm项目
npm init
-
安装
caliper-clinpm install --only=prod @hyperledger/[email protected]
-
测试是否安装成功
npx caliper --version
-
绑定区块链平台
-
由于Caliper采用了轻量级的部署方式,因此需要显式的绑定步骤指定要测试的平台及适配器版本,
caliper-cli会自动进行相应依赖项的安装。使用npx caliper bind命令进行绑定,命令所需的各项参数可以通过如下命令查看:user@ubuntu:~/benchmarks$ npx caliper bind --help Usage: caliper bind --caliper-bind-sut fabric --caliper-bind-sdk 1.4.1 --caliper-bind-cwd ./ --caliper-bind-args="-g" Options: --help Show help [boolean] -v, --version Show version number [boolean] --caliper-bind-sut The name of the platform to bind to [string] --caliper-bind-sdk Version of the platform SDK to bind to [string] --caliper-bind-cwd The working directory for performing the SDK install [string] --caliper-bind-args Additional arguments to pass to "npm install". Use the "=" notation when setting this parameter [string]
-
-
对于FISCO BCOS,可以采用如下方式进行绑定:
npx caliper bind --caliper-bind-sut fisco-bcos --caliper-bind-sdk latest
3.快速体验FISCO BCOS基准测试
-
在工作目录下下载预定义测试用例
git clone https://github.com/vita-dounai/caliper-benchmarks.git 或 git clone https://gitee.com/mirrors_hyperledger/caliper-benchmarks.git
4.修改配置
-
修改
/benchmarks/node_modules/\@hyperledger/caliper-fisco-bcos/lib/channelPromise.js第49行为:let emitter = emitters.get(seq); if(!emitter) { //Stale message receieved return; } emitter = emitter.emitter;
-
修改
/benchmarks/node_modules/\@hyperledger/caliper-fisco-bcos/lib/fiscoBcos.js第25行为:const Color = require('./common').Color;
-
修改
/benchmarks/node_modules/\@hyperledger/caliper-fisco-bcos/lib/web3lib/web3sync.js第27行,91行,118行分别修改为27行:
uuid = '0x' + uuid.replace(/-/g, '');
91行
extraData: '0x0'118行
extraData: '0x0' -
修改
/benchmarks/node_modules/\@hyperledger/caliper-fisco-bcos中的package.json文件,在dependencies字段中增加secp256k1": "^3.8.0,随后在该目录下执行npm i -
修改
/benchmarks/caliper-benchmarks/networks/fisco-bcos/4nodes1group/fisco-bcos.json,删除其中的command字段 -
修改
authentication字段中key,cert,ca字段的路径为ficso/nodes/127.0.0.1/sdk/目录下的对应文件位置 -
修改
/benchmarks/caliper-benchmarks/benchmarks/samples/fisco-bcos/helloworld/config.yaml,在末尾添加:monitor: type: - process process: - command: node0 arguments: fiscoBcosClientWorker.js multiOutput: avg - command: node1 arguments: fiscoBcosClientWorker.js multiOutput: avg - command: node2 arguments: fiscoBcosClientWorker.js multiOutput: avg - command: node3 arguments: fiscoBcosClientWorker.js multiOutput: avg interval: 0.5
5.执行helloworld测试(在benchmarks文件夹中执行)
npx caliper benchmark run --caliper-workspace caliper-benchmarks --caliper-benchconfig benchmarks/samples/fisco-bcos/helloworld/config.yaml --caliper-networkconfig networks/fisco-bcos/4nodes1group/fisco-bcos.json参数说明:
--caliper-workspace 指定工作目录
--caliper-benchconfig 指定测试配置文件
--caliper-networkconfig指定网络配置文件
本文参照:
https://github.com/nvm-sh/nvm#troubleshooting-on-linux
https://fisco-bcos-documentation.readthedocs.io/zh_CN/dev/docs/tutorial/caliper.html