diff --git a/test-network-k8s/docs/CALIPER.md b/test-network-k8s/docs/CALIPER.md new file mode 100644 index 0000000000..0383d10174 --- /dev/null +++ b/test-network-k8s/docs/CALIPER.md @@ -0,0 +1,197 @@ +# Benchmarking the performance using Hyperledger Caliper + +This document introduces how to use [Hyperledger Caliper](https://hyperledger.github.io/caliper/) to benchmark the performance of the Hyperledger Fabric environment created with test-network-k8s. + +[Fabric adapter manual of Hyperledger Caliper v0.6.0](https://hyperledger.github.io/caliper/v0.6.0/fabric-config/new/) only describes how to connect to test-network. So this document will explain how to benchmark the performance of the Kubernetes test network using Hyperledger Caliper and Asset Transfer Basic chaincode. + +The following documentation assumes that test-network-k8s and Hyperledger Caliper v0.6.0 are located on the same host. + +## Setting of test-network-k8s side + +As described in the README of test-network-k8s, launch the network, create a channel, and deploy and invoke the basic-asset-transfer smart contract: + +```shell +./network kind + +./network cluster init + +./network up + +./network channel create + +./network chaincode deploy asset-transfer-basic ../asset-transfer-basic/chaincode-java + +./network chaincode invoke asset-transfer-basic '{"Args":["InitLedger"]}' +``` + +REST API will not be used in the procedure described below, but the connection profile will be generated by launching it: +```shell +./network rest-easy +``` + +## Setting of Hyperledger Caliper side + +Following [Install manual of Hyperledger Caliper v0.6.0](https://hyperledger.github.io/caliper/v0.6.0/installing-caliper/), install Hyperledger Caliper from npm: + +```shell +git clone https://github.com/hyperledger/caliper-benchmarks.git +cd caliper-benchmarks +npm install --only=prod @hyperledger/caliper-cli@0.6.0 +npx caliper bind --caliper-bind-sut fabric:fabric-gateway +``` + +Copy the connection profile created in test-network-k8s environment to Caliper environment. + +```shell +cp /test-network-k8s/build/fabric-rest-sample-config/HLF_CONNECTION_PROFILE_ORG1 networks/fabric/connection-profile.json +``` +Edit "url" and "grpcOptions" in "peers" section of connection-profile.json as below: + +```json + "peers": { + "org1-peers": { + "url": "grpcs://org1-peer1.localho.st:443", + "tlsCACerts": { + "pem": " + }, + "grpcOptions": { + "ssl-target-name-override": "org1-peer1.localho.st", + "hostnameOverride": "org1-peer1.localho.st" + } + } + }, +``` + +Open networks/fabric/test-network.yaml and edit as below: + +```yaml +name: Caliper Benchmarks +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: fabcar + - id: fixed-asset + - id: marbles + - id: simple + - id: smallbank + - id: asset-transfer-basic + +organizations: + - mspid: Org1MSP + # Identities come from cryptogen created material for test-network + identities: + certificates: + - name: 'User1' + clientPrivateKey: + path: '/test-network-k8s/build/enrollments/org1/users/rcaadmin/msp/keystore/' + clientSignedCert: + path: '/test-network-k8s/build/enrollments/org1/users/rcaadmin/msp/signcerts/cert.pem' + connectionProfile: + path: 'networks/fabric/connection-profile.json' + discover: true +``` + +Currently, sample code for running a performance benchmark targeting asset-transfer-basic is not published on github. Therefore, use the sample code published in [Caliper's user manual to build a test workload.](https://hyperledger.github.io/caliper/vNext/fabric-tutorial/tutorials-fabric-existing/) + +As shown in "Step 3" of the above document, create workload/readAsset.js file and edit as below: + +```javascript +'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