当前位置: 首页 > article >正文

使用Caliper对Fabric地basic链码进行性能测试

如果你需要对fabric网络中地合约进行吞吐量、延迟等性能进行评估,可以使用Caliper来实现,会返回给你一份网页版的直观测试报告。下面是对test-network网络地basic链码地测试过程。

目录

    • 1. 建立caliper-workspace文件夹
    • 2. 安装npm等
    • 3. calipe安装
    • 4. 创建networks目录并编辑yaml文件
    • 5. 创建workload目录编写js文件
    • 6. 创建benchmarks目录并编写yaml文件
    • 7. 启动测试
    • 8. 查看结果

1. 建立caliper-workspace文件夹

建立caliper-workspace文件夹,文件夹的建立路径是相对地,我这里是在fabric-samples的同级目录下创建的,创建的路径不同后面的配置文件中关于私钥证书等地路径也是不同的。
在这里插入图片描述

2. 安装npm等

  • 进入caliper文件夹 ,安装npm
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

在这里插入图安装Node.js和npm片描述

  • 安装Node.js和npm
sudo apt-get install -y nodejs
  • 验证是否安装成功

在这里插入图片描述

3. calipe安装

  • 使用npm安装特定版本的@hyperledger/caliper包
npm install --only=prod @hyperledger/caliper@0.5.0

在这里插入图片描述

  • 使用 Caliper 工具绑定到 Hyperledger Fabric 网络
npx caliper bind --caliper-bind-sut fabric:2.2

在这里插入图片描述
注意后面所创建的目录结构如下:
在这里插入图片描述

4. 创建networks目录并编辑yaml文件

mkdir networks
cd networks/
vim networkConfig.yaml

写入:

name: Caliper test
version: "2.0.0"

caliper:
  blockchain: fabric

channels:
  # channelName of mychannel matches the name of the channel created by test network
  - channelName: mychannel
    # the chaincodeIDs of all the fabric chaincodes in caliper-benchmarks
    contracts:
    - id: basic

organizations:
  - mspid: Org1MSP
    # Identities come from cryptogen created material for test-network
    identities:
      certificates:
      - name: 'User1'
        clientPrivateKey:
          path: '../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/priv_sk'
        clientSignedCert:
          path: '../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/signcerts/User1@org1.example.com-cert.pem'
    connectionProfile:
      path: '../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml'
      discover: true

5. 创建workload目录编写js文件

cd ..
mkdir workload
cd workload
vim readAsset.js

写入:

'use strict';

const { WorkloadModuleBase } = require('@hyperledger/caliper-core');

class MyWorkload extends WorkloadModuleBase {
    constructor() {
        super();
    }

    async initializeWorkloadModule(workerIndex, totalWorkers, roundIndex, roundArguments, sutAdapter, sutContext) {
        await super.initializeWorkloadModule(workerIndex, totalWorkers, roundIndex, roundArguments, sutAdapter, sutContext);

        for (let i=0; i<this.roundArguments.assets; i++) {
            const assetID = `${this.workerIndex}_${i}`;
            console.log(`Worker ${this.workerIndex}: Creating asset ${assetID}`);
            const request = {
                contractId: this.roundArguments.contractId,
                contractFunction: 'CreateAsset',
                invokerIdentity: 'User1',
                contractArguments: [assetID,'blue','20','penguin','500'],
                readOnly: false
            };

            await this.sutAdapter.sendRequests(request);
        }
    }

    async submitTransaction() {
        const randomId = Math.floor(Math.random()*this.roundArguments.assets);
        const myArgs = {
            contractId: this.roundArguments.contractId,
            contractFunction: 'ReadAsset',
            invokerIdentity: 'User1',
            contractArguments: [`${this.workerIndex}_${randomId}`],
            readOnly: true
        };

        await this.sutAdapter.sendRequests(myArgs);
    }

    async cleanupWorkloadModule() {
        for (let i=0; i<this.roundArguments.assets; i++) {
            const assetID = `${this.workerIndex}_${i}`;
            console.log(`Worker ${this.workerIndex}: Deleting asset ${assetID}`);
            const request = {
                contractId: this.roundArguments.contractId,
                contractFunction: 'DeleteAsset',
                invokerIdentity: 'User1',
                contractArguments: [assetID],
                readOnly: false
            };

            await this.sutAdapter.sendRequests(request);
        }
    }
}

function createWorkloadModule() {
    return new MyWorkload();
}

module.exports.createWorkloadModule = createWorkloadModule;

6. 创建benchmarks目录并编写yaml文件

cd ..
mkdir benchmarks
cd benchmarks/
vim myAssetBenchmark.yaml

写入:

test:
    name: basic-contract-benchmark
    description: test benchmark
    workers:
      number: 2
    rounds:
      - label: readAsset
        description: Read asset benchmark
        txDuration: 30
        rateControl:
          type: fixed-load
          opts:
            transactionLoad: 2
        workload:
          module: workload/readAsset.js
          arguments:
            assets: 10
            contractId: basic

7. 启动测试

cd …

npx caliper launch manager --caliper-workspace ./ --caliper-networkconfig networks/networkConfig.yaml --caliper-benchconfig benchmarks/myAssetBenchmark.yaml --caliper-flow-only-test

在这里插入图片描述

8. 查看结果

然后会在workspace目录下产生一个报告:
在这里插入图片描述

打开后就是测试的tps、时延等信息:
在这里插入图片描述


http://www.kler.cn/news/162131.html

相关文章:

  • 【私藏】国内最全的电商API数据接口分享各种业务场景调用API代理的API接口教程
  • 查看Linux的Ubuntu的版本
  • pytorch 模型量化quantization
  • JAVA后端自学技能实操合集
  • Qt之基于QCustomPlot绘制直方图(Histogram),叠加正态分布曲线
  • vmware安装centos7总结
  • VSCODE 运行C程序缓慢解决方法之一
  • Ubuntu22.04安装Mariadb
  • C语言printf的输出格式大全及颜色字体打印
  • 微信小程序中block和View组件的使用区别
  • AI发展下服务器的选择非常重要
  • mysql 链接超时的几个参数详解
  • 嵌入式总线技术学习(文章链接汇总)
  • C语言——指针(五)
  • 【C/PTA —— 15.结构体2(课内实践)】
  • 3D材质编辑:制作被火烧的木头
  • ERP数据仓库模型
  • 数学建模-二氧化碳排放及时空分布测度
  • Ubuntu安装nvidia GPU显卡驱动教程
  • SAP数据一键拉取!利用零代码ETL工具快速实现数据同步
  • 【C/PTA —— 15.结构体2(课外实践)】
  • CPU密集型和IO密集型与CPU内核之间的关系
  • Fabric 画布缩放、拖动、初始化大小
  • 人工智能_机器学习059_非线性核函数_poly核函数_rbf核函数_以及linear核函数效果对比---人工智能工作笔记0099
  • Docker快速入门(编译源码辅助技)
  • AWS攻略——使用中转网关(Transit Gateway)连接同区域(Region)VPC
  • Android 默认打开应用的权限
  • bat脚本之加法
  • Linux_vi/vim编辑器
  • Qt基础之四十:Qt Installer Framework(QtIFW)的编译、使用和实现原理