ciliper踩坑记录
  mzIiiVpJOHDT 2023年11月02日 73 0

1 介绍

Caliper 是一个区块链性能基准测试框架,它允许用户使用预定义的用例测试不同的区块链解决方案,并获得一组性能测试结果。

目前支持的性能指标:

  • 成功率
  • 事务吞吐量
  • 事务延迟(最小值、最大值、平均值、百分比)
  • 资源消耗(CPU、内存、网络 IO 等)

2.安装

在ubuntu20.04安装caliper遇到不少问题,花费了大量时间解决,现记录下来避免后人踩坑。切记,以下要一步步按照步骤执行,本人跳步骤吃了不少亏。

2.1 安装前准备

安装caliper需要nodejs,npm等多个工具,因此先提前把工具安装好。

2.1.1. 安装 make,g++ 编译工具

sudo apt-get install make g++

2.1.2. 安装node.js

ubuntu 支持 nodesouce 的二进制安装脚本,命令如下:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

sudo apt-get install -y nodejs

如果没用过curl,需要先执行apm install curl,可能会遇到有些网站无法访问,执行以下步骤换源:

2.1

# 备份

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 删除原文件

sudo rm /etc/apt/sources.list

# 新建文件

sudo vim /etc/apt/sources.list

2.2 输入i进入编辑状态,将下列内容粘贴进去,输入Esc,再输入:wq,保存并退出

阿里源

deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

这里要把文件删除,替换成这块。如果只是在最后加上或者换成清华源,有些还是会404.这个源较稳定。


安装完成后查看 node 与 npm 的版本,如果版本过低,后续可能还会报错

ciliper踩坑记录_install

执行npm install npm -g,即可将npm升级至最新版本。

2.1.3. 安装 node-gyp

npm 全局安装 node-gyp:

sudo npm install -g node-gyp

执行完可能有warning,可以执行node-nyp list命令,能显示出版本就ok。

2.1.4. 安装 Docker

由于 apt 源使用HTTPS以确保软件下载过程中不被篡改。因此,我们首先需要添加使用HTTPS传输的软件包以及CA证书。

$ sudo apt-get install \

apt-transport-https \

ca-certificates \

curl \

software-properties-common

为了确认所下载软件包的合法性,需要添加软件源的 GPG 秘钥

$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

然后,我们需要向 sources.list 中添加 Docker 软件源

$ sudo add-apt-repository \

"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \

$(lsb_release -cs) \

stable"

更新 apt 软件包缓存,并安装 docker-ce:

$ sudo apt-get update

$ sudo apt-get install docker-ce

查看 Docker 版本:

$ docker -v

启动 Docker CE

$ sudo systemctl enable docker

$ sudo systemctl start docker

建立 docker 用户组(ps:这步执行的时候可能提示已存在,就不需要再建立 docker 用户组了)

$ sudo groupadd docker

将当前用户加入 docker 用户组

$ sudo usermod -aG docker $USER

测试 Docker 是否安装正确

$ docker run hello-world

Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world

9db2ca6ccae0: Pull complete

Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc

Status: Downloaded newer image for hello-world:latest


Hello from Docker!

This message shows that your installation appears to be working correctly.


To generate this message, Docker took the following steps:

1. The Docker client contacted the Docker daemon.

2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

(amd64)

3. The Docker daemon created a new container from that image which runs the

executable that produces the output you are currently reading.

4. The Docker daemon streamed that output to the Docker client, which sent it

to your terminal.


To try something more ambitious, you can run an Ubuntu container with:

$ docker run -it ubuntu bash


Share images, automate workflows, and more with a free Docker ID:

https://hub.docker.com/


For more examples and ideas, visit:

https://docs.docker.com/engine/userguide/

配置镜像加速器

国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在则创建)

{

"registry-mirrors": [

"https://registry.docker-cn.com"

]

}

之后重新启动服务

$ sudo systemctl daemon-reload

$ sudo systemctl restart docker

2.1.5. 安装 Docker-compose

$ sudo curl -L "https://get.daocloud.io/docker/compose/releases/download/2.13.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

这里本来是https://github.com/docker/compose/releases/download/1.22.0/docker-compose,但是执行下来需要科学上网,就换成了get.daocloud.io网站。版本可以根据自己需求选,我这里用的是2.13.0版本的。

$ sudo chmod +x /usr/local/bin/docker-compose

查看 Docker compose 版本

$ docker-compose --version

2.2 安装caliper

2.2.1.下载caliper-benchmarks

git clone https://github.com/hyperledger/caliper-benchmarks.git cd caliper-benchmarks

cd caliper-benchmarks

2.2.2.本地安装caliper-cli

1 初始化项目

npm init -y

执行完后,会在当前目录生成package.json文件

2 安装caliper-cli

npm install --notallow=prod @hyperledger/caliper-cli@0.3.0

执行完后,会将依赖下载到当前目录下的node_modules文件夹下

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/

2.2.3. 运行测试用例

这里测试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

3.参考链接

https://caohuilong.github.io/2018/10/10/caliper%E5%AE%89%E8%A3%85%E8%AE%B0%E5%BD%95/

https://blog.51cto.com/u_14834727/3031774


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
mzIiiVpJOHDT
作者其他文章 更多

2023-11-02