成功跑完caliper自帶例子之后,本人嘗試使用caliper來(lái)測(cè)試自己部署的多機(jī)fabric環(huán)境。
被測(cè)fabric網(wǎng)絡(luò)拓?fù)?/h1>
1orderer劫樟、3peer吗垮、kafka共識(shí)垛吗、無(wú)ca、native啟動(dòng)(非docker)烁登。
IP | 節(jié)點(diǎn) | 域名 |
---|---|---|
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 | 無(wú)需 |
Caliper配置文件
基準(zhǔn)測(cè)試配置
{
"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ù)制到對(duì)應(yīng)的地點(diǎn)怯屉。
執(zhí)行測(cè)試
node ./benchmark/simple/main.js -c ./config-test.json -n ./fabric-test.json
image.png
注:上圖為測(cè)試流程,部分日志是本人調(diào)試所添加代碼產(chǎn)生饵沧。
生成報(bào)告
image.png
遇到的問(wèn)題
安裝問(wèn)題:
- error: [join-channel.js]: Failed to join peers, TypeError: Cannot read property 'getConnectivityState' of undefined
問(wèn)題: grpc的版本錯(cuò)誤 必須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
問(wèn)題:nodejs的版本要是8.x(不能太低也不能太高)
執(zhí)行問(wèn)題
- error: [Peer.js]: sendProposal - timed out after:120000
問(wèn)題:超時(shí)時(shí)間設(shè)置過(guò)短锨络。 src/fabric/e2eUtils.js里調(diào)整超時(shí)時(shí)間 -
channel已存在要設(shè)置:
image.png - 由于是已經(jīng)啟動(dòng)好的鏈碼,如果已經(jīng)安裝上chaincode再次測(cè)試會(huì)報(bào)錯(cuò)狼牺,需要調(diào)整代碼羡儿。可以看Pr162的解決辦法是钥,在區(qū)塊鏈網(wǎng)絡(luò)配置中chaincodes項(xiàng)加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í)行的時(shí)候 chaincodes的deployed為true
"chaincodes": [{"id": "simple11", "path": "contract/fabric/simple/go", "language":"golang", "version": "v2", "channel": "mychannel","deployed": true}],
其他問(wèn)題可以在https://github.com/hyperledger/caliper/issues 查找
fabric性能影響的要素
- 交易復(fù)雜度
- solo/kafka
- 出塊時(shí)間&&出塊交易個(gè)數(shù)
- leveldb/couchdb
- 機(jī)器cpu、內(nèi)存資源
- 網(wǎng)絡(luò)拓?fù)洳渴鹎闆r
- ...