成功跑完caliper自带例子之后,本人尝试使用caliper来测试自己部署的多机fabric环境。
被测fabric网络拓扑
1orderer、3peer、kafka共识、无ca、native启动(非docker)。
IP | 节点 | 域名 |
---|---|---|
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
}
}
区块链网络配置
{
"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/[email protected]/msp/keystore/80a9e436031bf3df0a79ea7523d66dfb04ac659ef5b637dc945dae0b07949abe_sk",
"cert": "network/fabric/simple/crypto-config-test/ordererOrganizations/example.com/users/[email protected]/msp/signcerts/[email protected]"
},
"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/[email protected]/msp/keystore/90a3c8fafce618c26fbb8be65497ba40e03e60684e7288b346dfa370f93cf06a_sk",
"cert": "network/fabric/simple/crypto-config-test/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]"
},
"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/[email protected]/msp/keystore/bc3d0a927a1a6d9d46cf273be11242eaa45141e2e7aa8492b7c0116257079588_sk",
"cert": "network/fabric/simple/crypto-config-test/peerOrganizations/org2.example.com/users/[email protected]/msp/signcerts/[email protected]"
},
"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"
}
}
注:配置文件中关于fabric的msp等文件需要生成好以后复制到对应的地点。
执行测试
node ./benchmark/simple/main.js -c ./config-test.json -n ./fabric-test.json
注:上图为测试流程,部分日志是本人调试所添加代码产生。
生成报告
遇到的问题
安装问题:
- 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(不能太低也不能太高)
执行问题
- error: [Peer.js]: sendProposal - timed out after:120000
问题:超时时间设置过短。 src/fabric/e2eUtils.js里调整超时时间 -
channel已存在要设置:
- 由于是已经启动好的链码,如果已经安装上chaincode再次测试会报错,需要调整代码。可以看Pr162的解决办法,在区块链网络配置中chaincodes项加deployed参数,并且在src/fabric/install-chaincode.js文件以及src/fabric/instantiate-chaincode.js文件中加入相应的处理逻辑:
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}],
安装成功后再执行的时候 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性能影响的要素
- 交易复杂度
- solo/kafka
- 出块时间&&出块交易个数
- leveldb/couchdb
- 机器cpu、内存资源
- 网络拓扑部署情况
- ...