Fabric性能测试工具Caliper安装使用

文章目录
Pre-requisites

  1. 安装 make,g++ 编译工具
  2. 安装node.js
  3. 安装 node-gyp
  4. 安装 Docker
  5. 安装 Docker-compose
    Clone caliper repository
    Install fabric SDKs
    Run benchmark
    Bugs
    运行测试遇到 REQUEST_TIMEOUT 的问题:
    Pre-requisites
    需要安装的基础环境如下:

make,g++
NodeJS 8.X
node-gyp
Docker
Docker-compose

  1. 安装 make,g++ 编译工具
sudo apt-get install make g++
  1. 安装node.js
    ubuntu 支持 nodesouce 的二进制安装脚本,命令如下:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

安装完成后查看 node 与 npm 的版本:

$ node -v
v8.12.0
$ npm -v
6.4.1
  1. 安装 node-gyp
    npm 全局安装 node-gyp:
sudo npm install -g node-gyp
  1. 安装 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"

以上命令会添加稳定版本的Docker CE apt 镜像源。

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

$ sudo apt-get update

$ sudo apt-get install docker-ce

查看 Docker 版本:

$ docker -v
Docker version 18.06.0-ce, build 0ffa825

启动 Docker CE

$ sudo systemctl enable docker
$ sudo systemctl start docker

建立 docker 用户组

默认情况下,docker 命令会使用 Unix socket 与 Docker 引擎通讯。而只有 root 用户和 docker 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用 root 用户。因此,更好地做法是将需要使用 docker 的用户加入 docker 用户组。

$ sudo groupadd docker

其实一般按照上面的方法安装 Docker 后就已经创建好 docker 用户组了,可以使用 $ cat /etc/group | grep docker 命令来验证,所以就不需要再建立 docker 用户组了,再建立也会报错提示用户组已存在的。

将当前用户加入 docker 用户组:

$ sudo usermod -aG docker $USER

下次登录时即可方便的使用 docker 命令。

测试 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 拉取镜像有时会遇到困难,此时可以配置镜像加速器。Docker 官方和国内很多云服务商都提供了国内加速器服务,例如:

Docker 官方提供的中国 registry mirror https://registry.docker-cn.com
七牛云加速器 https://reg-mirror.qiniu.com/
当配置某一个加速器地址之后,若发现拉取不到镜像,请切换到另一个加速器地址。

国内各大云服务商均提供了 Docker 镜像加速服务,建议根据运行 Docker 的云平台选择对应的镜像加速服务。

我们以 Docker 官方加速器 https://registry.docker-cn.com 为例进行介绍。

在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在则创建)

{
  "registry-mirrors": [
    "https://registry.docker-cn.com"
  ]
}

之后重新启动服务

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
  1. 安装 Docker-compose
    通过二进制包来安装,从 官方 GitHub Release 处直接下载编译好的二进制文件即可。
$ sudo curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

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

查看 Docker compose 版本

$ docker-compose --version
docker-compose version 1.22.0, build f46880fe

Clone caliper repository
从 GitHub 克隆 caliper 代码仓库:

git clone https://github.com/hyperledger/caliper.git

进入 caliper 目录并运行 npm install 安装依赖包:

cd caliper/
npm install

Install fabric SDKs
在 caliper 目录下本地安装 fabric SDKs:

npm install grpc@1.10.1 fabric-ca-client fabric-client

以上命令默认安装 fabric 最新版本的 SDKs,但是由于 caliper 验证过的最新版本是 v1.1.0,所以我们最好安装 v1.1.0 版本:

npm install fabric-ca-client@1.1.0 fabric-client@1.1.0

Run benchmark
性能测试示例在benchmark目录下,用法如下:

node benchmark/simple/main.js -c yourconfig.json -n yournetwork.json

-c 用于指定区块链的配置文件,不指定的话默认为config.json;
-n 用于指定区块链网络配置文件,不指定的话由-c指定的配置文件定义。
运行一个 simple 的实例:

node benchmark/simple/main.js

生成的报告如下:

在这里插入图片描述

原文链接:https://blog.csdn.net/cao0507/article/details/83002800

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值