一、安裝使用
在上一篇中其時啓動的就是一個默認的Solo版本,其實在實際的應用場景中基本不會使用此場景來進行應用。但是對於一些學習和熟悉Fabric的初步知識的人可以說有一個比較直觀的方式。還是有很大的方便性的。
Caliper的使用其實主要是配置文件的使用,在不研究源碼的前提下,掌握好各種測試文件的配置,是掌握其應用的主要的方式。使用Caliper將配置搞定,其基本就可以移植到實際場景中的應用配置。
二、配置文件的分析
配置文件主要類,一類是測試文件,一類是網絡文件。關於Fabric本身的測試文件這裏暫時不做關注,當然,在測試壓力時,最終還是要進行配置的,但這裏主要先講這兩類配置文件。這兩類文件主要在benchmarks,networks兩個文件夾下。默認的Solo配置兩個文件是:
D:\caliper-benchmarks\benchmarks\scenario\simple\config.yaml
D:\caliper-benchmarks\networks\fabric\fabric-v1.4.1\2org1peergoleveldb\fabric-go.yaml
其代碼打開如下:
config.yaml:
---
test:
name: simple
description: This is an example benchmark for caliper, to test the backend DLT's
performance with simple account opening & querying transactions
clients:
type: local
number: 1
rounds:
- label: open
description: Test description for the opening of an account through the deployed chaincode
txNumber:
- 100
rateControl:
- type: fixed-rate
opts:
tps: 50
arguments:
money: 10000
callback: benchmarks/scenario/simple/open.js
- label: query
description: Test description for the query performance of the deployed chaincode
txNumber:
- 100
rateControl:
- type: fixed-rate
opts:
tps: 100
callback: benchmarks/scenario/simple/query.js
- label: transfer
description: Test description for transfering money between accounts
txNumber:
- 100
rateControl:
- type: fixed-rate
opts:
tps: 50
arguments:
money: 100
callback: benchmarks/scenario/simple/transfer.js
monitor:
type:
- docker
docker:
name:
- all
interval: 1
fabric-go.yaml
name: Fabric
version: "1.0"
mutual-tls: false
caliper:
blockchain: fabric
command:
start: export FABRIC_VERSION=1.4.1;docker-compose -f networks/fabric/docker-compose/2org1peergoleveldb/docker-compose.yaml up -d;sleep 3s
end: docker-compose -f networks/fabric/docker-compose/2org1peergoleveldb/docker-compose.yaml down;(test -z \"$(docker ps -aq)\") || docker rm $(docker ps -aq);(test -z \"$(docker images dev* -q)\") || docker rmi $(docker images dev* -q);rm -rf /tmp/hfc-*
info:
Version: 1.4.1
Size: 2 Orgs with 1 Peer
Orderer: Solo,
Distribution: Single Host
StateDB: GoLevelDB
clients:
client0.org1.example.com:
client:
organization: Org1
credentialStore:
path: /tmp/hfc-kvs/org1
cryptoStore:
path: /tmp/hfc-cvs/org1
clientPrivateKey:
path: networks/fabric/config_solo/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/key.pem
clientSignedCert:
path: networks/fabric/config_solo/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]
client0.org2.example.com:
client:
organization: Org2
credentialStore:
path: /tmp/hfc-kvs/org2
cryptoStore:
path: /tmp/hfc-cvs/org2
clientPrivateKey:
path: networks/fabric/config_solo/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/keystore/key.pem
clientSignedCert:
path: networks/fabric/config_solo/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/signcerts/[email protected]
channels:
mychannel:
configBinary: networks/fabric/config_solo/mychannel.tx
created: false
orderers:
- orderer.example.com
peers:
peer0.org1.example.com:
eventSource: true
peer0.org2.example.com:
eventSource: true
chaincodes:
- id: marbles
version: v0
language: golang
path: fabric/samples/marbles/go
metadataPath: src/fabric/samples/marbles/go/metadata
- id: drm
version: v0
language: golang
path: fabric/scenario/drm/go
- id: simple
version: v0
language: golang
path: fabric/scenario/simple/go
- id: smallbank
version: v0
language: golang
path: fabric/scenario/smallbank/go
organizations:
Org1:
mspid: Org1MSP
peers:
- peer0.org1.example.com
certificateAuthorities:
- ca.org1.example.com
adminPrivateKey:
path: networks/fabric/config_solo/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/key.pem
signedCert:
path: networks/fabric/config_solo/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]
Org2:
mspid: Org2MSP
peers:
- peer0.org2.example.com
certificateAuthorities:
- ca.org2.example.com
adminPrivateKey:
path: networks/fabric/config_solo/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/keystore/key.pem
signedCert:
path: networks/fabric/config_solo/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp/signcerts/[email protected]
orderers:
orderer.example.com:
url: grpc://localhost:7050
grpcOptions:
ssl-target-name-override: orderer.example.com
peers:
peer0.org1.example.com:
url: grpc://localhost:7051
grpcOptions:
ssl-target-name-override: peer0.org1.example.com
grpc.keepalive_time_ms: 600000
peer0.org2.example.com:
url: grpc://localhost:8051
grpcOptions:
ssl-target-name-override: peer0.org2.example.com
grpc.keepalive_time_ms: 600000
certificateAuthorities:
ca.org1.example.com:
url: http://localhost:7054
httpOptions:
verify: false
registrar:
- enrollId: admin
enrollSecret: adminpw
ca.org2.example.com:
url: http://localhost:8054
httpOptions:
verify: false
registrar:
- enrollId: admin
enrollSecret: adminpw
這兩個文件的配置細節在網上有官方的具體說明:
https://hyperledger.github.io/caliper/vLatest/installing-caliper/
這裏重點對關心的幾個細節進行說明一下:
1、Client的數量
這個數量默認是1,根據測試的環境(硬件的配置)可以適當調高,比如這次測試就設置成4或者5的時候兒TPS最高。然後開始下降。
2、Tps的限制
這個類似於上面的Client,默認是50可以設置到1000以上。
3、交易的限制
這個設置不是明顯,估計得和以後的塊配置以及出塊時間設置後會有一些聯繫。
4、地址的配置
5、CA的配置
這個可以省略掉,不影響測試的使用。
從兩個配置文件的實際使用來看,在公司的雲服務器上的測試速度Tps最高是900左右。寫入的速度不超過200.這個可能和單機有關。
三、總結
從上述的分析來看,Caliper的Solo測試還是比較方便的,傻瓜的方式即可使用,但是問題是,這樣的測試有多大的意義,能不能給實際應用提供一個參考。還是隻能做爲跑通的一個用例的實驗,這都需要認真的對待和考慮。