中文官方文档 :
Hyperledger Caliper手册 - 汇智网 (hubwiz.com)
config.yaml
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
---
test:
name: Food Trace
description: This is a FoodTrace benchmark of FISCO BCOS for caliper
clients:
type: local
number: 1
rounds:
- label: new-food
description: Test performance of <newFood> name
txNumber:
- 10
rateControl:
- type: fixed-rate
opts:
tps: 1
callback: benchmarks/samples/fisco-bcos/trace/newFood.js
- label: get-food
description: Test performance of <getFood> name
txNumber:
- 10
rateControl:
- type: fixed-rate
opts:
tps: 1
callback: benchmarks/samples/fisco-bcos/trace/getFood.js
monitor:
type:
- process
process:
- command: node0
arguments: fiscoBcosClientWorker.js
multiOutput: avg
- command: node1
arguments: fiscoBcosClientWorker.js
multiOutput: avg
interval: 0.5
==需要修改的地方
rounds:
- label: new-food 测试名称
description: Test performance of <newFood> name 测试介绍
txNumber:
- 10
rateControl:
- type: fixed-rate
opts:
tps: 1
callback: benchmarks/samples/fisco-bcos/trace/newFood.js
- label: get-food
description: Test performance of <getFood> name
txNumber:
- 10
rateControl:
- type: fixed-rate
opts:
tps: 1
callback: benchmarks/samples/fisco-bcos/trace/getFood.js
可以通过txNumber
或txDuration
字段指定测试的交易发送数量或执行时间
tps 每秒压测次数
callback 压测文件路径
test.name | 在报告中显示的基准测试名称 |
test.description | 在报告中显示的基准测试的详细描述 |
test.clients | 工作进程相关的配置 |
test.clients.type | 当前未用 |
test.clients.number | 指定用于执行工作负载的工作进程数量 |
test.rounds | 对象数组,每个成员都描述一个测试轮次的设置 |
test.rounds[i].label | 测试轮次的简称,通常对应所提交交易的类型 |
test.rounds[i].txNumber | 在测试轮次中Caliper需要提交的交易数量 |
test.rounds[i].txDuration | 测试轮次持续的时长 |
test.rounds[i].rateControl | 对象,描述轮次的速率控制器 |
test.rounds[i].callback | 工作负载模块的路径 |
test.rounds[i].arguments | 传递给工作负载模块的参数 |
monitor
项负责对测试所使用的性能监视器的进行配置。每项配置项的解释如下:
-
monitor.type,需要指定为
docker
,指对docker容器进行监控; -
monitor.docker.name,一个包含所有要监视的节点的docker容器名称列表,名字必须以
http://
开头,其后跟随”{节点的IP}:{节点docker daemon端口}/{docker容器的名称}”; -
monitor.interval,监视器的采样间隔,单位为秒。
如果是在本地搭好的链,则可以添加本地性能监视器,相应地监视器的配置更改如下:
monitor:
type:
- process
process:- command: node0
multiOutput: avg - command: node1
multiOutput: avg - command: node2
multiOutput: avg - command: node3
multiOutput: avg
interval: 0.1
- command: node0
其中每项配置项的解释如下:
-
monitor.type,需要指定为
process
,只对进程进行监控; -
monitor.process,一个包含所有要监视的进称列表,其中每个进程的command属性为一个正则表达式,表示进程名称;每个进程还可以有一个arguments属性(未在上述示例中使用到),表示进程的参数。Caliper会先使用ps命令搜索commad + arguments,然后匹配以得到目标的进程的进程ID及系统资源的使用情况。每个进程的multiOutput属性用于指定结果的输出方式,目前支持平均值(avg)及总和(sum)两种方式;
-
monitor.interval,监视器的采样间隔,单位为秒。
需要注意的是,进程监控目前暂不支持监控进程对网络和磁盘的使用情况
fisco-bcos.json
{
"caliper": {
"blockchain": "fisco-bcos"
},
"fisco-bcos": {
"config": {
"privateKey": "bcec428d5205abe0f0cc8a734083908d9eb8563e31f943d760786edf42ad67dd",
"account": "0x0ff8981ebc130c7874ac7093a4d0c0e3d4f36b08"
},
"network": {
"nodes": [
{
"ip": "127.0.0.1",
"rpcPort": "8545",
"channelPort": "20201"
},
{
"ip": "127.0.0.1",
"rpcPort": "8546",
"channelPort": "20202"
},
{
"ip": "127.0.0.1",
"rpcPort": "8547",
"channelPort": "20203"
},
{
"ip": "127.0.0.1",
"rpcPort": "8548",
"channelPort": "20204"
}
],
"authentication": {
"key": "/Users/taoyahui/fisco/nodes/127.0.0.1/sdk/node.key",
"cert": "/Users/taoyahui/fisco/nodes/127.0.0.1/sdk/node.crt",
"ca": "/Users/taoyahui/fisco/nodes/127.0.0.1/sdk/ca.crt"
},
"groupID": 1,
"timeout": 100000
},
"smartContracts": [
{
"id": "newenergy",
"path": "src/fisco-bcos/newenergy/NewEnergy.sol",
"language": "solidity",
"version": "v0"
}
]
},
"info": {
"Version": "2.0.0",
"Size": "4 Nodes",
"Distribution": "Single Host"
}
}
==需要修改的地方
1.smartContracts(压测所用合约路径)
2.network(节点配置)
3.config(压测所用用户的地址及公钥)
压测文件.js
get方法压测
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
module.exports.info = 'get Food';
let bc, contx;
module.exports.init = function (blockchain, context, args) {
// Do nothing
bc = blockchain;
contx = context;
return Promise.resolve();
};
module.exports.run = function () {
return bc.queryState(contx, 'trace', 'v0', '20230201001', 'getFood(uint256)');
};
module.exports.end = function () {
// Do nothing
return Promise.resolve();
};
修改的地方
module.exports.info = 'get Food';//修改为压测方法名称
return bc.queryState(contx, 'trace', 'v0', '20230201001', 'getFood(uint256)');
//‘trace’ 修改为压测合约名称 ‘getFood(uint256)’为调用方法
set方法压测
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
module.exports.info = 'new food';
let bc, contx;
let txnPerBatch;
module.exports.init = function (blockchain, context, args) {
txnPerBatch = 10;
bc = blockchain;
contx = context;
return Promise.resolve();
};
/**
* Generates simple workload
* @return {Object} array of json objects
*/
function generateWorkload() {
let workload = [];
for (let i = 0; i < txnPerBatch; i++) {
let w = {
'transaction_type': 'newFood(string,uint256,string,uint8)',
'name': "苹果",
'traceNumber': 20230201001 + i,
'traceName': '0x0ff8981ebc130c7874ac7093a4d0c0e3d4f36b08s',
'quality': 5,
};
workload.push(w);
}
return workload;
}
module.exports.run = function () {
let args = generateWorkload();
return bc.invokeSmartContract(contx, 'trace', 'v0', args, null);
};
module.exports.end = function () {
// Do nothing
return Promise.resolve();
};
==修改的地方
module.exports.info = 'new food';//压测方法名
let w = {
'transaction_type': 'newFood(string,uint256,string,uint8)',//压测方法函数签名 uint一定要指定uint256
'name': "苹果", //传递参数对应合约
'traceNumber': 20230201001 + i, //
'traceName': '0x0ff8981ebc130c7874ac7093a4d0c0e3d4f36b08s',
'quality': 5,
};
function newFood(string name, uint256 traceNumber, string traceName, uint8 quality)
public returns(address)
启动方法
在/opt/benchmarks目录下执行命令:
npx caliper benchmark run --caliper-workspace caliper-benchmarks --caliper-benchconfig benchmarks/samples/fisco-bcos/trace/config.yaml --caliper-networkconfig networks/fisco-bcos/test-trace/fisco-bcos.json
–caliper-workspace 工作目录
–caliper-benchconfig 配置文件
–caliper-networkconfig 网络配置