• 区块链安全应用------压力测试


    测试要求:

    • 1. 对以下AccountManager智能合约进行压测(基础要求set函数测试,balanceOf涵为20分加分项)
    • 2. 在本地链进行测试,需要监控本地进程的资源使用情况。每个进程的multiOutput属性为Avg
    • 3. 需要将每一个更改的配置文件截图,和执行命令截图放在word中。提交word代码。

    第一步:智能合约添加到caliper-bench中,操作和代码截图

    在benchmarks/caliper-benchmarks/src/fisco-bcos/文件下创建AccountManager文件存放智能合约

    1. mkdir -p /root/benchmarks/caliper-benchmarks/src/fisco-bcos/AccountManager
    2. cd /root/benchmarks/caliper-benchmarks/src/fisco-bcos/AccountManager
    3. vim AccountManager.sol

    第二步:更改网络配置参数,操作和代码截图

    • a) 在/root/benchmarks/caliper-benchmarks/networks/fisco-bcos目录下创建test目录
    • b) 在该目录下添加网络配置文件fisco-bcos.json
    1. mkdir -p /root/benchmarks/caliper-benchmarks/networks/fisco-bcos/test
    2. cd /root/benchmarks/caliper-benchmarks/networks/fisco-bcos/test
    3. vim fisco-bcos.json

     

    1. {
    2. "caliper": {
    3. "blockchain": "fisco-bcos",
    4. "command": {
    5. "start": "docker-compose -f networks/fisco-bcos/4nodes1group/docker-compose.yaml up -d; sleep 3s",
    6. "end": "docker-compose -f networks/fisco-bcos/4nodes1group/docker-compose.yaml down"
    7. }
    8. },
    9. "fisco-bcos": {
    10. "config": {
    11. "privateKey": "bcec428d5205abe0f0cc8a734083908d9eb8563e31f943d760786edf42ad67dd",
    12. "account": "0x64fa644d2a694681bd6addd6c5e36cccd8dcdde3"
    13. },
    14. "network": {
    15. "nodes": [
    16. {
    17. "ip": "127.0.0.1",
    18. "rpcPort": "8914",
    19. "channelPort": "20914"
    20. },
    21. {
    22. "ip": "127.0.0.1",
    23. "rpcPort": "8915",
    24. "channelPort": "20915"
    25. },
    26. {
    27. "ip": "127.0.0.1",
    28. "rpcPort": "8916",
    29. "channelPort": "20916"
    30. },
    31. {
    32. "ip": "127.0.0.1",
    33. "rpcPort": "8917",
    34. "channelPort": "20917"
    35. }
    36. ],
    37. "authentication": {
    38. "key": "/home/myy/Desktop/benchmarks/caliper-benchmarks/networks/fisco-bcos/4nodes1group/sdk/node.key",
    39. "cert": "/home/myy/Desktop/benchmarks/caliper-benchmarks/networks/fisco-bcos/4nodes1group/sdk/node.crt",
    40. "ca": "/home/myy/Desktop/benchmarks/caliper-benchmarks/networks/fisco-bcos/4nodes1group/sdk/ca.crt"
    41. },
    42. "groupID": 1,
    43. "timeout": 100000
    44. },
    45. "smartContracts": [
    46. {
    47. "id": "helloworld",
    48. "path": "src/fisco-bcos/helloworld/HelloWorld.sol",
    49. "language": "solidity",
    50. "version": "v0"
    51. },
    52. {
    53. "id": "parallelok",
    54. "path": "src/fisco-bcos/transfer/ParallelOk.sol",
    55. "language": "solidity",
    56. "version": "v0"
    57. },
    58. {
    59. "id": "dagtransfer",
    60. "address": "0x0000000000000000000000000000000000005002",
    61. "language": "precompiled",
    62. "version": "v0"
    63. },
    64. {
    65. "id": "AccountManager",
    66. "path": "src/fisco-bcos/AccountManager/AccountManager.sol" ,
    67. "language": "solidity" ,
    68. "version": "v1"
    69. }
    70. ]
    71. },
    72. "info": {
    73. "Version": "2.0.0",
    74. "Size": "4 Nodes",
    75. "Distribution": "Single Host"
    76. }
    77. }

    第三步:测试配置文件参数,操作和代码截图

    • a)在/root/benchmarks/caliper-benchmarks/benchmarks/samples/fisco-bcos目录下创建AccountManager文件
    • b)编辑配置测试文件配置
    1. mkdir -p /root/benchmarks/caliper-benchmarks/benchmarks/samples/fiscobcos/AccountManager
    2. cd /root/benchmarks/caliper-benchmarks/benchmarks/samples/fiscobcos/AccountManager
    3. vim config.yaml

    1. #
    2. # Licensed under the Apache License, Version 2.0 (the "License");
    3. # you may not use this file except in compliance with the License.
    4. # You may obtain a copy of the License at
    5. #
    6. # http://www.apache.org/licenses/LICENSE-2.0
    7. #
    8. # Unless required by applicable law or agreed to in writing, software
    9. # distributed under the License is distributed on an "AS IS" BASIS,
    10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11. # See the License for the specific language governing permissions and
    12. # limitations under the License.
    13. #
    14. ---
    15. test:
    16. name: AccountManager
    17. description: This is a AccountManager benchmark of FISCO BCOS for caliper
    18. clients:
    19. type: local
    20. number: 1
    21. rounds:
    22. - label: setAccount
    23. description: Test performance of getting account
    24. txNumber:
    25. - 10000
    26. rateControl:
    27. - type: fixed-rate
    28. opts:
    29. tps: 1000
    30. callback: /home/myy/Desktop/benchmarks/caliper-benchmarks/benchmarks/samples/fisco-bcos/AccountManager/set.js
    31. monitor:
    32. type:
    33. - docker
    34. - process
    35. docker:
    36. name:
    37. - node0
    38. - node1
    39. - node2
    40. - node3
    41. process:
    42. - command: node
    43. arguments: fiscoBcosClientWorker.js
    44. multiOutput: avg
    45. interval: 0.5

    第四步:测试文件编写,操作和代码截图

    • a)在/root/benchmarks/caliper-benchmarks/benchmarks/samples/fiscobcos/AccountManager目录下编辑测试文件配置  
    1. cd /root/benchmarks/caliper-benchmarks/benchmarks/samples/fiscobcos/AccountManager
    2. vim set.js

    1. /*
    2. * Licensed under the Apache License, Version 2.0 (the "License");
    3. * you may not use this file except in compliance with the License.
    4. * You may obtain a copy of the License at
    5. *
    6. * http://www.apache.org/licenses/LICENSE-2.0
    7. *
    8. * Unless required by applicable law or agreed to in writing, software
    9. * distributed under the License is distributed on an "AS IS" BASIS,
    10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11. * See the License for the specific language governing permissions and
    12. * limitations under the License.
    13. */
    14. 'use strict';
    15. module.exports.info = ' setting account';
    16. let initMoney = 100000000;
    17. let bc, contx;
    18. let txnPerBatch;
    19. module.exports.init = function (blockchain, context, args) {
    20. txnPerBatch = 1;
    21. bc = blockchain;
    22. contx = context;
    23. return Promise.resolve();
    24. };
    25. /**
    26. * Generates simple workload
    27. * @return {Object} array of json objects
    28. */
    29. function generateWorkload() {
    30. let workload = [];
    31. for (let i = 0; i < txnPerBatch; i++) {
    32. let w = {
    33. 'transaction_type': 'set(string,uint256)',
    34. 'name': 'hello! - from ' + process.pid.toString(),
    35. 'num': initMoney
    36. };
    37. workload.push(w);
    38. }
    39. return workload;
    40. }
    41. module.exports.run = function () {
    42. let args = generateWorkload();
    43. return bc.invokeSmartContract(contx, 'AccountManager', 'v0', args, null);
    44. };
    45. module.exports.end = function () {
    46. // Do nothing
    47. return Promise.resolve();
    48. };

    第五步:运行压测结果命令和结果截图

    运行benchmark代码:

    1. cd benchmarks
    2. npx caliper benchmark run --caliper-workspace /home/myy/Desktop/benchmarks/caliper-benchmarks --caliper-benchconfig /home/myy/Desktop/benchmarks/caliper-benchmarks/benchmarks/samples/fisco-bcos/AccountManager/config.yaml --caliper-networkconfig /home/myy/Desktop/benchmarks/caliper-benchmarks/networks/fisco-bcos/4nodes1group/fisco-bcos.json

    第六步:生成报告截图

  • 相关阅读:
    vue 部分知识点总结
    【Arduino IDE 2.0他来了】
    C++实现轻量级RPC分布式网络通信框架
    5分钟搞懂MySQL - 行转列
    virtualbox虚拟机安装Ubuntu异常处理:FATAL: NO bootable medium found! System halted
    Oracle11gr2 + plsql 配置
    Spring源码阅读(spring-framework-5.2.24)
    (一)笔记.net core学习之主机和主机配置
    数据清洗(data clean)
    在 Rocky 中使用 FreeRDP 远程连接 Windows 机器
  • 原文地址:https://blog.csdn.net/2201_76041915/article/details/138167382