联盟链 Hyperledger Fabric v1.4.4 性能测试工具 Stupid 使用方式

在区块链测试方面来说,相较于 Caliper,stupid 这个开源工具更加的轻量化,且配置更加容易,可以对正在运行的区块链直接进行测试。但缺点就是无法像 Caliper 那样自定义测试脚本,且不知道在哪能看到成功率这一项数据等等,希望作者后面能补上吧~
附上作者项目地址:https://github.com/guoger/stupid

一、环境简述

本次进行压测的区块链环境,为CentOS 7,fabric 和 samples 版本均为 v1.4.4,且已经是启动状态的 byfn 网络。
若还不熟悉搭建示例区块链网络同学的可以点这里的链接看我之前的文章哈,先搭建起来,才好进行下一步。 >从零搭建区块链示例网络<

二、stupid 搭建

1. 下载

这里可以用 git 来把项目克隆下来

> 当前位置:/root
[root@localhost ~]# git clone https://github.com/guoger/stupid

2. golang 代理

作者的步骤是说拉下来后进入里面执行 go build,可是大部分人由于网络原因很难把 golang 模块拉下来,所以我们先要使用 https://goproxy.cn/ 的方法,为我们的环境打上 golang 代理:

[root@localhost ~]# export GO111MODULE=on
[root@localhost ~]# export GOPROXY=https://goproxy.cn

3. 构建

上好了代理,就可以进入 stupid 文件夹内执行构建啦,会发现速度快很多。

> 当前路径:/root/stupid
[root@localhost stupid]# go build

构建完成后,能看到当前文件夹下生成一个名为 stupid 的执行文件,就表明成功啦~

三、进行压测

1. 配置文件 config.json

这个 stupid 简单就简单在只需要配置 1 个文件,就可以即刻开始压测。要注意证书签名路径以及端口指向均要设置为当前已经启动的区块链网络的配置,在这里我就都设置指向 byfn 的配置。
接下来我放出修改前和修改后的 config 文件来作为对比把~
【修改前】

{
  "peer_addr": "peer0.org1.example.com:7051",		#(peer 节点地址与端口)
  "orderer_addr": "orderer.example.com:7050",		#(orderer 节点地址与端口)
  "channel": "mychannel",							#(通道名称)
  "chaincode": "mycc",								#(链码名称,区块链内指定的那个,不是文件名称)
  "args": ["put", "key", "value"],					#【压测可调整参数】(指定测试项目方法,及传入参数)
  "mspid": "Org1MSP",								#(MSP 的 ID)
  "private_key": "/path/to/private.key",			#(私钥文件)
  "sign_cert": "/path/to/sign.cert",				#(签名证书)
  "tls_ca_certs": ["/path/to/peer/tls/ca/cert","/path/to/orderer/tls/ca/cert"],		#(两个证书,第一个是 peer 的,第二个是 orderer 的)
  "num_of_conn": 20,								#【压测可调整参数】
  "client_per_conn": 40								#【压测可调整参数】
}

配置里最后两项我还是奉上作者的原话把,我自己的理解怕给大家造成困扰

num_of_conn: number of gRPC connection established between client/peer, client/orderer. If you think client has not put enough pressure on Fabric, increase this.

client_per_conn: number of clients per connection used to send proposals to peer. If you think client has not put enough pressure on Fabric, increase this.

【修改后】

{
  "peer_addr": "peer0.org1.example.com:7051",
  "orderer_addr": "orderer.example.com:7050",
  "channel": "mychannel",
  "chaincode": "mycc",
  "args": ["query", "a"],		#(若要测试 transfer,则对应修改为 "args": ["invoke","a","b","10"])
  "mspid": "Org1MSP",
  "private_key": "/root/go/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/96f4c10ebf4e8de1da3ea7f541172d7b61831a07c9519f2806072c16cd04a3da_sk",
  "sign_cert": "/root/go/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]",
  "tls_ca_certs": ["/root/go/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem","/root/go/src/github.com/hyperledger/fabric-samples/first-network/crypto-config/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem"],
  "num_of_conn": 20,
  "client_per_conn": 40
}

2. 启动

执行 stupid,指定配置文件 config 与要发送的交易数,即可开始压测

root@localhost stupid]# ./stupid config.json 1000

这里关于第三个参数同样我贴出作者的原话给大家

Run
Execute ./stupid config.json 40000 to generate 40000 transactions to Fabric.
Set this to integer times of batchsize, so that last block is not cut due to timeout. For example, if you have batch size of 500, set this to 500, 1000, 40000, 100000, etc

2G 内存 2 核虚拟机的 stupid 压测结果:

[root@localhost stupid]# ./stupid config.json 100
Start sending transactions...

Time     0.10s	Block    556	Tx     10
Time     0.17s	Block    557	Tx     10
Time     0.18s	Block    558	Tx     10
Time     0.20s	Block    559	Tx     10
Time     0.22s	Block    560	Tx     10
Time     0.26s	Block    561	Tx     10
Time     0.27s	Block    562	Tx     10
Time     0.28s	Block    563	Tx     10
Time     0.29s	Block    564	Tx     10
Time     0.30s	Block    565	Tx     10
tx: 100, duration: 302.373519ms, tps: 330.716791

顺便提示一下,结果中的 Tx 10,是可以修改的,在 fabric 下 configtx.yaml 文件中的出块策略,对其调整后就会变化,如下所示:

> 文件位置:fabric-samples/first-network/configtx.yaml 出块策略部分

Orderer: &OrdererDefaults
    OrdererType: solo
    BatchTimeout: 2s
    BatchSize:
        MaxMessageCount: 10		#(比如说这条,我把他调整为 500,stupid 结果里的 Tx 就变为 500 了)
        AbsoluteMaxBytes: 99 MB
        PreferredMaxBytes: 512 KB

至此本文结束,感谢大家阅读~~~~

猜你喜欢

转载自blog.csdn.net/Phather/article/details/106241342