欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

caliper的应用之二Solo版本的分析使用

程序员文章站 2022-07-14 16:05:39
...

一、安装使用

在上一篇中其时启动的就是一个默认的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测试还是比较方便的,傻瓜的方式即可使用,但是问题是,这样的测试有多大的意义,能不能给实际应用提供一个参考。还是只能做为跑通的一个用例的实验,这都需要认真的对待和考虑。

相关标签: blockchain