From 4b9b4753e4afad04f4dea9f063f076626b66f1ab Mon Sep 17 00:00:00 2001 From: takayuki-nagai Date: Fri, 5 Jul 2024 09:05:40 +0000 Subject: [PATCH 1/9] Add document about how to benchmark the performance using Hyperledger Caliper Signed-off-by: takayuki-nagai --- test-network-k8s/docs/CALIPER.md | 197 +++++++++++++++++++++++++++++++ test-network-k8s/docs/README.md | 1 + 2 files changed, 198 insertions(+) create mode 100644 test-network-k8s/docs/CALIPER.md 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 Date: Thu, 11 Jul 2024 20:03:43 +0900 Subject: [PATCH 2/9] Update test-network-k8s/docs/CALIPER.md Co-authored-by: Tatsuya Sato Signed-off-by: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> --- test-network-k8s/docs/CALIPER.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-network-k8s/docs/CALIPER.md b/test-network-k8s/docs/CALIPER.md index 0383d10174..891447d097 100644 --- a/test-network-k8s/docs/CALIPER.md +++ b/test-network-k8s/docs/CALIPER.md @@ -192,6 +192,7 @@ test: After creating the above files, you can run a performance benchmark with the following command, which will create some assets and measure the time it takes to reference the assets. -```bash +```shell + npx caliper launch manager --caliper-workspace . --caliper-benchconfig benchmarks/myAssetBenchmark.yaml --caliper-networkconfig networks/fabric/test-network.yaml ``` From 1025919b8f23a2ba8768256dcd009234041a2cd9 Mon Sep 17 00:00:00 2001 From: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> Date: Thu, 11 Jul 2024 20:03:57 +0900 Subject: [PATCH 3/9] Update test-network-k8s/docs/CALIPER.md Co-authored-by: Tatsuya Sato Signed-off-by: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> --- test-network-k8s/docs/CALIPER.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-network-k8s/docs/CALIPER.md b/test-network-k8s/docs/CALIPER.md index 891447d097..7a9c17d6a8 100644 --- a/test-network-k8s/docs/CALIPER.md +++ b/test-network-k8s/docs/CALIPER.md @@ -62,7 +62,8 @@ Edit "url" and "grpcOptions" in "peers" section of connection-profile.json as be }, ``` -Open networks/fabric/test-network.yaml and edit as below: +Open networks/fabric/test-network.yaml and edit it as below: + ```yaml name: Caliper Benchmarks From e3f84c679dfa2962611a6bb0aed4bef93de176a8 Mon Sep 17 00:00:00 2001 From: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> Date: Thu, 11 Jul 2024 20:04:14 +0900 Subject: [PATCH 4/9] Update test-network-k8s/docs/CALIPER.md Co-authored-by: Tatsuya Sato Signed-off-by: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> --- test-network-k8s/docs/CALIPER.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-network-k8s/docs/CALIPER.md b/test-network-k8s/docs/CALIPER.md index 7a9c17d6a8..de6033ccf8 100644 --- a/test-network-k8s/docs/CALIPER.md +++ b/test-network-k8s/docs/CALIPER.md @@ -99,7 +99,8 @@ organizations: 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/) +Currently, sample code for running a performance benchmark targeting asset-transfer-basic is not published on the Caliper repository. 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: From 1fdde51834393a9aa3b025eabf46ed3049124f97 Mon Sep 17 00:00:00 2001 From: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> Date: Thu, 11 Jul 2024 20:04:23 +0900 Subject: [PATCH 5/9] Update test-network-k8s/docs/CALIPER.md Co-authored-by: Tatsuya Sato Signed-off-by: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> --- test-network-k8s/docs/CALIPER.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-network-k8s/docs/CALIPER.md b/test-network-k8s/docs/CALIPER.md index de6033ccf8..3d11b3ea08 100644 --- a/test-network-k8s/docs/CALIPER.md +++ b/test-network-k8s/docs/CALIPER.md @@ -102,7 +102,8 @@ organizations: Currently, sample code for running a performance benchmark targeting asset-transfer-basic is not published on the Caliper repository. 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: +As shown in "Step 3" of the above document, create workload/readAsset.js file and edit it as below: + ```javascript 'use strict'; From 0954912028f90e86eff70127a1baff329d488e76 Mon Sep 17 00:00:00 2001 From: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> Date: Thu, 11 Jul 2024 20:04:30 +0900 Subject: [PATCH 6/9] Update test-network-k8s/docs/CALIPER.md Co-authored-by: Tatsuya Sato Signed-off-by: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> --- test-network-k8s/docs/CALIPER.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-network-k8s/docs/CALIPER.md b/test-network-k8s/docs/CALIPER.md index 3d11b3ea08..a0da79fd7b 100644 --- a/test-network-k8s/docs/CALIPER.md +++ b/test-network-k8s/docs/CALIPER.md @@ -170,7 +170,8 @@ function createWorkloadModule() { module.exports.createWorkloadModule = createWorkloadModule; ``` -As shown in "Step 4" of the above document, create benchmarks/myAssetBenchmark.yaml file and edit as below: +As shown in "Step 4" of the above document, create benchmarks/myAssetBenchmark.yaml file and edit it as below: + ```yaml test: From d5702cf58dbfbf8e4b5186935f9554747fa43ced Mon Sep 17 00:00:00 2001 From: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> Date: Thu, 11 Jul 2024 20:06:32 +0900 Subject: [PATCH 7/9] Update test-network-k8s/docs/CALIPER.md Co-authored-by: Tatsuya Sato Signed-off-by: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> --- test-network-k8s/docs/CALIPER.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-network-k8s/docs/CALIPER.md b/test-network-k8s/docs/CALIPER.md index a0da79fd7b..9059e874e9 100644 --- a/test-network-k8s/docs/CALIPER.md +++ b/test-network-k8s/docs/CALIPER.md @@ -91,7 +91,8 @@ organizations: certificates: - name: 'User1' clientPrivateKey: - path: '/test-network-k8s/build/enrollments/org1/users/rcaadmin/msp/keystore/' + path: '/test-network-k8s/build/enrollments/org1/users/org1admin/msp/keystore/key.pem' + clientSignedCert: path: '/test-network-k8s/build/enrollments/org1/users/rcaadmin/msp/signcerts/cert.pem' connectionProfile: From 20d8fd6a00a272c834a8a464726ec92a3c918768 Mon Sep 17 00:00:00 2001 From: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> Date: Thu, 11 Jul 2024 20:06:41 +0900 Subject: [PATCH 8/9] Update test-network-k8s/docs/CALIPER.md Co-authored-by: Tatsuya Sato Signed-off-by: takayuki-nagai <57936858+takayuki-nagai@users.noreply.github.com> --- test-network-k8s/docs/CALIPER.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-network-k8s/docs/CALIPER.md b/test-network-k8s/docs/CALIPER.md index 9059e874e9..8b2d673606 100644 --- a/test-network-k8s/docs/CALIPER.md +++ b/test-network-k8s/docs/CALIPER.md @@ -94,7 +94,8 @@ organizations: path: '/test-network-k8s/build/enrollments/org1/users/org1admin/msp/keystore/key.pem' clientSignedCert: - path: '/test-network-k8s/build/enrollments/org1/users/rcaadmin/msp/signcerts/cert.pem' + path: '/test-network-k8s/build/enrollments/org1/users/org1admin/msp/signcerts/cert.pem' + connectionProfile: path: 'networks/fabric/connection-profile.json' discover: true From 4a1db5bc387c2aa7b8f0cf6575d293e71c101559 Mon Sep 17 00:00:00 2001 From: takayuki-nagai Date: Wed, 17 Jul 2024 08:39:52 +0000 Subject: [PATCH 9/9] Update with review comments. Signed-off-by: takayuki-nagai --- test-network-k8s/docs/CALIPER.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test-network-k8s/docs/CALIPER.md b/test-network-k8s/docs/CALIPER.md index 8b2d673606..bc83ed27e6 100644 --- a/test-network-k8s/docs/CALIPER.md +++ b/test-network-k8s/docs/CALIPER.md @@ -2,7 +2,7 @@ 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. +[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. Furthermore, these chaincodes need to be executed as services to run in a K8s environment, but this is not supported by default, requiring customization. So we will explain how to benchmark the performance of the Kubernetes test network using Hyperledger Caliper and Asset Transfer Basic chaincode, which is most basic in current sample chaincodes. The following documentation assumes that test-network-k8s and Hyperledger Caliper v0.6.0 are located on the same host. @@ -45,7 +45,7 @@ Copy the connection profile created in test-network-k8s environment to Caliper e ```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: +Replace `*.test-network.svc.cluster.local` with `*.localho.st` in "url" and "grpcOptions" section of connection-profile.json as below: ```json "peers": { @@ -61,6 +61,7 @@ Edit "url" and "grpcOptions" in "peers" section of connection-profile.json as be } }, ``` +`*.localho.st` is wildcard domain defined for accessing K8s pod from external network via Nginx ingress controller. Please see [Working with Kubernetes](KUBERNETES.md) document for details. Open networks/fabric/test-network.yaml and edit it as below: