资中移动网站建设,网页制作专业以后好找工作吗,厦门网站seo建设,WordPress手机写文章如果你需要对fabric网络中地合约进行吞吐量、延迟等性能进行评估#xff0c;可以使用Caliper来实现#xff0c;会返回给你一份网页版的直观测试报告。下面是对test-network网络地basic链码地测试过程。 目录 1. 建立caliper-workspace文件夹2. 安装npm等3. calipe安装4. 创建…如果你需要对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
sudo apt-get install -y nodejs验证是否安装成功 3. calipe安装
使用npm安装特定版本的hyperledger/caliper包
npm install --onlyprod hyperledger/caliper0.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.0caliper:blockchain: fabricchannels:# channelName of mychannel matches the name of the channel created by test network- channelName: mychannel# the chaincodeIDs of all the fabric chaincodes in caliper-benchmarkscontracts:- id: basicorganizations:- mspid: Org1MSP# Identities come from cryptogen created material for test-networkidentities:certificates:- name: User1clientPrivateKey:path: ../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/User1org1.example.com/msp/keystore/priv_skclientSignedCert:path: ../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/User1org1.example.com/msp/signcerts/User1org1.example.com-cert.pemconnectionProfile:path: ../fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yamldiscover: true5. 创建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 i0; ithis.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 i0; ithis.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-benchmarkdescription: test benchmarkworkers:number: 2rounds:- label: readAssetdescription: Read asset benchmarktxDuration: 30rateControl:type: fixed-loadopts:transactionLoad: 2workload:module: workload/readAsset.jsarguments:assets: 10contractId: basic7. 启动测试
cd …
npx caliper launch manager --caliper-workspace ./ --caliper-networkconfig networks/networkConfig.yaml --caliper-benchconfig benchmarks/myAssetBenchmark.yaml --caliper-flow-only-test8. 查看结果
然后会在workspace目录下产生一个报告
打开后就是测试的tps、时延等信息