實戰(zhàn)Caliper測試多機Fabric環(huán)境

成功跑完caliper自帶例子之后,本人嘗試使用caliper來測試自己部署的多機fabric環(huán)境。

被測fabric網(wǎng)絡(luò)拓撲

1orderer、3peer、kafka共識、無ca、native啟動(非docker)。

IP 節(jié)點 域名
10.254.186.164 orderer orderer.example.com
10.254.186.164 peer peer0.org1.example.com
10.254.247.165 peer peer1.org1.example.com
10.254.207.154 peer peer0.org2.example.com
10.254.186.164 kafka 無需

Caliper配置文件

基準測試配置

{
  "blockchain": {
    "type": "fabric",
    "config": "benchmark/simple/fabric-test.json"
  },
  "command" : {
  },
  "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",
      "txNumber" : [1000, 1000, 1000,1000, 1000, 1000],
      "rateControl" : [{"type": "fixed-rate", "opts": {"tps" : 50}}, {"type": "fixed-rate", "opts": {"tps" : 100}}, {"type": "fixed-rate", "opts": {"tps" : 150}},{"type": "fixed-rate", "opts": {"tps" : 200}},{"type": "fixed-rate", "opts": {"tps" : 250}},{"type": "fixed-rate", "opts": {"tps" : 300}}],
      "arguments": { "money": 10000 },
      "callback" : "benchmark/simple/open.js"
    },
    {
      "label" : "query",
      "txNumber" : [5000, 5000,5000, 5000,5000, 5000],
      "rateControl" : [{"type": "fixed-rate", "opts": {"tps" : 100}}, {"type": "fixed-rate", "opts": {"tps" : 200}},{"type": "fixed-rate", "opts": {"tps" : 300}},{"type": "fixed-rate", "opts": {"tps" : 400}},{"type": "fixed-rate", "opts": {"tps" : 500}},{"type": "fixed-rate", "opts": {"tps" : 600}}],
      "callback" : "benchmark/simple/query.js"
    }]
  },
  "monitor": {
    "type": ["docker", "process"],
    "docker":{
      "name": ["all"]
    },
    "process": [
      {
        "command" : "node",
        "arguments" : "local-client.js",
        "multiOutput" : "avg"
      }
    ],
    "interval": 1
  }
}

區(qū)塊鏈網(wǎng)絡(luò)配置

{
  "blockchain": {
    "type": "fabric",
    "config": "benchmark/simple/fabric-test.json"
  },
  "command" : {
  },
  "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",
      "txNumber" : [1000, 1000, 1000,1000, 1000, 1000],
      "rateControl" : [{"type": "fixed-rate", "opts": {"tps" : 50}}, {"type": "fixed-rate", "opts": {"tps" : 100}}, {"type": "fixed-rate", "opts": {"tps" : 150}},{"type": "fixed-rate", "opts": {"tps" : 200}},{"type": "fixed-rate", "opts": {"tps" : 250}},{"type": "fixed-rate", "opts": {"tps" : 300}}],
      "arguments": { "money": 10000 },
      "callback" : "benchmark/simple/open.js"
    },
    {
      "label" : "query",
      "txNumber" : [5000, 5000,5000, 5000,5000, 5000],
      "rateControl" : [{"type": "fixed-rate", "opts": {"tps" : 100}}, {"type": "fixed-rate", "opts": {"tps" : 200}},{"type": "fixed-rate", "opts": {"tps" : 300}},{"type": "fixed-rate", "opts": {"tps" : 400}},{"type": "fixed-rate", "opts": {"tps" : 500}},{"type": "fixed-rate", "opts": {"tps" : 600}}],
      "callback" : "benchmark/simple/query.js"
    }]
  },
  "monitor": {
    "type": ["docker", "process"],
    "docker":{
      "name": ["all"]
    },
    "process": [
      {
        "command" : "node",
        "arguments" : "local-client.js",
        "multiOutput" : "avg"
      }
    ],
    "interval": 1
  }
}
[dc2-user@cli caliper]$ cat benchmark/simple/fabric-test.json
{
  "fabric": {
    "cryptodir": "network/fabric/simple/crypto-config-test",
    "network": {
      "orderer": {
        "url": "grpcs://10.254.186.164:7050",
        "mspid": "OrdererMSP",
        "domain": "example.com",
    "user": {
          "key": "network/fabric/simple/crypto-config-test/ordererOrganizations/example.com/users/Admin@example.com/msp/keystore/80a9e436031bf3df0a79ea7523d66dfb04ac659ef5b637dc945dae0b07949abe_sk",
          "cert": "network/fabric/simple/crypto-config-test/ordererOrganizations/example.com/users/Admin@example.com/msp/signcerts/Admin@example.com-cert.pem"
        },
        "server-hostname": "orderer.example.com",
        "tls_cacerts": "network/fabric/simple/crypto-config-test/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt"
      },
      "org1": {
        "name": "Org1MSP",
        "mspid": "Org1MSP",
        "domain": "org1.example.com",
    "user": {
          "key": "network/fabric/simple/crypto-config-test/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/90a3c8fafce618c26fbb8be65497ba40e03e60684e7288b346dfa370f93cf06a_sk",
          "cert": "network/fabric/simple/crypto-config-test/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/Admin@org1.example.com-cert.pem"
        },
        "peer1": {
          "requests": "grpcs://10.254.186.164:7051",
          "events": "grpcs://10.254.186.164:7053",
          "server-hostname": "peer0.org1.example.com",
          "tls_cacerts": "network/fabric/simple/crypto-config-test/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
        },
        "peer2": {
          "requests": "grpcs://10.254.247.165:7051",
          "events": "grpcs://10.254.247.165:7053",
          "server-hostname": "peer1.org1.example.com",
          "tls_cacerts": "network/fabric/simple/crypto-config-test/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt"
        }
      },
      "org2": {
        "name": "Org2MSP",
        "mspid": "Org2MSP",
        "domain": "org2.example.com",
    "user": {
          "key": "network/fabric/simple/crypto-config-test/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/bc3d0a927a1a6d9d46cf273be11242eaa45141e2e7aa8492b7c0116257079588_sk",
          "cert": "network/fabric/simple/crypto-config-test/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts/Admin@org2.example.com-cert.pem"
        },
        "peer1": {
          "requests": "grpcs://10.254.207.154:7051",
          "events": "grpcs://10.254.207.154:7053",
          "server-hostname": "peer0.org2.example.com",
          "tls_cacerts": "network/fabric/simple/crypto-config-test/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
        }
      }
    },
    "channel": [
      {
        "name": "mychannel",
        "config": "network/fabric/simple/mychannel.tx",
    "deployed": true,
        "organizations": ["org1", "org2"]
      }
    ],
    "chaincodes": [{"id": "simple11", "path": "contract/fabric/simple/go", "language":"golang", "version": "v2", "channel": "mychannel","deployed": true}],
    "endorsement-policy": {
      "identities": [
        {
          "role": {
            "name": "member",
            "mspId": "Org1MSP"
          }
        },
        {
          "role": {
            "name": "member",
            "mspId": "Org2MSP"
          }
        },
        {
          "role": {
            "name": "admin",
            "mspId": "Org1MSP"
          }
        }
      ],
      "policy": { "2-of": [{"signed-by": 0},{"signed-by": 1}]}
    },
    "context": {
      "open": "mychannel",
      "query": "mychannel"
    }
  },
  "info" : {
    "Version": "1.1.0",
    "Size": "3 Peers",
    "Orderer": "Kafka",
    "Distribution": "Multi Hosts"
  }
}

注:配置文件中關(guān)于fabric的msp等文件需要生成好以后復(fù)制到對應(yīng)的地點。

執(zhí)行測試

node ./benchmark/simple/main.js -c ./config-test.json -n ./fabric-test.json
image.png

注:上圖為測試流程,部分日志是本人調(diào)試所添加代碼產(chǎn)生。

生成報告

image.png

遇到的問題

安裝問題:

  • error: [join-channel.js]: Failed to join peers, TypeError: Cannot read property 'getConnectivityState' of undefined
    問題: grpc的版本錯誤 必須v.1.10.1
  • info: [bench-flow.js]: #######Caliper Test######
    (node:25548) DeprecationWarning: grpc.load: Use the @grpc/proto-loader module with grpc.loadPackageDefinition instead
    問題:nodejs的版本要是8.x(不能太低也不能太高)

執(zhí)行問題

  • error: [Peer.js]: sendProposal - timed out after:120000
    問題:超時時間設(shè)置過短。 src/fabric/e2eUtils.js里調(diào)整超時時間
  • channel已存在要設(shè)置:


    image.png
  • 由于是已經(jīng)啟動好的鏈碼,如果已經(jīng)安裝上chaincode再次測試會報錯,需要調(diào)整代碼。可以看Pr162的解決辦法,在區(qū)塊鏈網(wǎng)絡(luò)配置中chaincodes項加deployed參數(shù),并且在src/fabric/install-chaincode.js文件以及src/fabric/instantiate-chaincode.js文件中加入相應(yīng)的處理邏輯:
    https://github.com/hyperledger/caliper/pull/162
    具體:在安裝初始化之前chaincodes的deployed為false:
    "chaincodes": [{"id": "simple11", "path": "contract/fabric/simple/go", "language":"golang", "version": "v2", "channel": "mychannel","deployed": false}],

安裝成功后再執(zhí)行的時候 chaincodes的deployed為true

 "chaincodes": [{"id": "simple11", "path": "contract/fabric/simple/go", "language":"golang", "version": "v2", "channel": "mychannel","deployed": true}],

其他問題可以在https://github.com/hyperledger/caliper/issues 查找

fabric性能影響的要素

  • 交易復(fù)雜度
  • solo/kafka
  • 出塊時間&&出塊交易個數(shù)
  • leveldb/couchdb
  • 機器cpu、內(nèi)存資源
  • 網(wǎng)絡(luò)拓撲部署情況
  • ...
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容