如果是自定义的合约压测的话,并且使用`test-nw`下的`fisco-bcos.json`配置的话,就代表是用自己的本地链进行压测
如果是caliper的docker进行压测,就要去修改`4nodes1group`下面的`fisco-bcos.json`配置。
使用什么本地还是docker压测,本质上都是一样的,只是位置不同罢了
首先要准备需要测试合约的`config.yaml`配置文件,里面配置了压测的各种要求,这里提供第一套`trace`的`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
multiOutput: avg
- command: node1
multiOutput: avg
- command: node2
multiOutput: avg
interval: 0.1
首先要注意`monitor`
注意最后`monitor`这一部分,这里使用的是本地的所以是这种写法,如果要使用`docker`的话,`type`类型改为`docker`,其他的也要相应的修改,具体参考官网的自定义测试用例那模块:https://fisco-bcos-documentation.readthedocs.io/zh-cn/dev/docs/tutorial/caliper.html
其次要注意`rounds`
test项负责对测试内容进行配置。配置主要集中在round字段中指定如何对区块链系统进行测试。每一个测试可以包含多轮,每一轮可以向区块链发起不同的测试请求。具体要tarce合约测试,测试中包含两轮,分别对合约的newFood.js接口和getFood.js接口进行测试。在每一轮测试中,可以通过txNumber或txDuration字段指定测试的交易发送数量或执行时间,并通过rateControl字段指定交易发送时的速率控制器,在本节的示例中,使用了QPS为1000的匀速控制器,更多速率控制器的介绍可以参考官方文档。
其次需要配置`test-nw`目录下的`fisco-bcos.json`文件,这里还是提供一份`trace`项目的`fisco-bcos.json`参考:
{
"caliper": {
"blockchain": "fisco-bcos"
},
"fisco-bcos": {
"config": {
"privateKey": "bcec428d5205abe0f0cc8a734083908d9eb8563e31f943d760786edf42ad67dd",
"account": "0x0ff8981ebc130c7874ac7093a4d0c0e3d4f36b08"
},
"network": {
"nodes": [
{
"ip": "127.0.0.1",
"rpcPort": "8545",
"channelPort": "20200"
},
{
"ip": "127.0.0.1",
"rpcPort": "8546",
"channelPort": "20201"
},
{
"ip": "127.0.0.1",
"rpcPort": "8547",
"channelPort": "20202"
}
],
"authentication": {
"key": "/root/tools/nodes/127.0.0.1/sdk/sdk.key",
"cert": "/root/tools/nodes/127.0.0.1/sdk/sdk.crt",
"ca": "/root/tools/nodes/127.0.0.1/sdk/ca.crt"
},
"groupID": 1,
"timeout": 100000
},
"smartContracts": [
{
"id": "trace",
"path": "src/fisco-bcos/trace/Trace.sol",
"language": "solidity",
"version": "v0"
}
]
},
"info": {
"Version": "2.0.0",
"Size": "3 Nodes",
"Distribution": "Single Host"
}
}
首先注意`network.smartContracts`,这个配置项是配置合约的
指定要测试的合约,Caliper会在启动时想后端区块链系统部署合约。目前FISCO BCOS适配器支持通过language字段指定两种类型的合约——Solidity合约和预编译合约,当测试合约为Solidity合约时,language字段需要指定为solidity,当测试合约为预编译合约时,language字段需要指定为precompiled。当测试合约为预编译合约时,需要在address字段中指定预编译合约的地址,否则需要在path字段中指定Solidity合约的路径。
其次注意`network.nodes`
一个包含了所有要连接节点的列表,列表中每一项需要指明被连接节点的IP地址、RPC端口及Channel端口号,所有端口号需要和节点的配置文件保持一致。
bug合集
- 2024.08.04-14:42:20.329 error [caliper] [invokeSmartContract.js] Failed to invoke smart contract trace: {"error":"timeout"}

首先是network.nodes的bug
根据第一套题目的要求,我们进行到这里的时候,已经让其他所有节点将node3节点拉入了黑名单,所以就会遇到:
2024.08.04-14:42:20.329 error [caliper] [invokeSmartContract.js] Failed to invoke smart contract trace: {"error":"timeout"}
原因归根结底还是node3被拉黑的问题,因为我们使用的是本地自己的链
解决办法:
取消之前修改的所有拉黑并且重启节点
vi nodes/127.0.0.1/node*/config.ini
bash nodes/127.0.0.1/stop_all.sh && bash nodes/127.0.0.1/start_all.sh
- 2024.08.04-14:34:25.443 error [caliper] [invokeSmartContract.js] Failed to invoke smart contract trace: {"error":{"code":-40009,"data":null,"message":"Don't send request to this node who doesn't belong to the group"},"id":1,"jsonrpc":"2.0"}

一直重复输出或是warn的报错,其次还有
2024.08.04-14:34:33.450 error [caliper] [defaultTest] ------ Failed 'new-food' testing with the following error -----
这类问题是,之前不是因为node3被拉黑的,但我们还有新建了一个node4,因此我就尝试了,把`fisco-bcos`里面`network.nodes`的节点3的改成4,节点分别为0、1、2、4,但这样就会遇到这里提到的报错,原因是node4好像为加入群组?只是单方面连接了
解决办法:
改回来,再使用第一种方法
以上的报错都是源于node3被禁用,但我们更改题目是不合理的,这里提供最好的解决办法,另一种思路:
既然node3不能用,那我们干脆删了node3就好,只留下node0、1、2三个节点测试足以
修改`vi caliper-benchmarks/networks/fisco-bcos/test-nw/fisco-bcos.json`,把`info.Size`的"4 Nodes"修改为"3 Nodes";`network.nodes`数组里面,node3那一块全部删除。
其次,修改`vi caliper-benchmarks/benchmarks/samples/fisco-bcos/trace/config.yaml` ,把`monitor.process`里面的node3那一块全部删除
注意,以上提供的模板也进行到这一步
,
{
"ip": "127.0.0.1",
"rpcPort": "8548",
"channelPort": "20203"
}

- command: node4
multiOutput: avg


被折叠的 条评论
为什么被折叠?



