Caliper Testing tutorial.
With Caliper you can get the following performance indicators:
1. Success rate
2. Transaction/Read throughput
3. Transaction/Read latency (minimum, maximum, average)
4. Resource consumption (CPU, Memory, Network IO, …)
Prerequisite
A running HLF network . In this case , supplychain network.
NodeJS must be installed
For supplychain network, following test is going to be performed.
1. Create product.
2. mint product.
we can test only function written in chaincode.ie . caliper test only chaincode functionality.
The inetarction with HLF is smae way as of REST api middleware, using user details and connection profile.
Need a networkconfiguration file: says. newtork.yaml.
This is for blockchain interaction.
The user details specified here will be used to interact with blockchain.
We also need to specify the network profile file as well as MSPID, Contracts, channel etc.
In this case , the file placed inside the folder network .
If you want use , diffrenet org or diffrenet user, can create different network file.
Benchmark Configuration: This file specifies the test functionality details in yaml format. productBenchmark.yaml will be in this case.
It will be in a folder called benchmark. The file have two round of test for different functionality. This can be many as you like.
There can be mutiple benchmark file for diffrenet functionality with differnet types of test.
Each round block contains the following:
label - the unique header label to use for the round.
description - a description of the round being run.
txDuration - the specification of the test duration, in seconds.
txNumber — the number of transactions to perform.
rateControl - a rate control type, with options.
workload - the workload module to use, with arguments to pass to the module.
All arguments passed are available as roundArguments within the workload module.
There are multiple types of rate controllers like fixed-load, fixed-rate, fixed-feedback-rate, linear-rate, etc
Test Workload Module
The workload module interacts with the deployed smart contract during the benchmark round.
The workload module extends the Caliper class WorkloadModuleBase from caliper-core.
The workload module provides three overrides:
initializeWorkloadModule - used to initialize any required items for the benchmark
submitTransaction - used to interact with the smart contract method during the monitored phase of the benchmark
cleanupWorkloadModule - used to clean up after the completion of the benchmark
Inside script sendRequest ,
We need to pass the following details to sendRequests :
contractId — the name of the smart contract that is to be used and is present within the Caliper network configuration file.
contractFunction — the specific function within the smart contract to invoke.
contractArguments — the arguments to pass to the smart contract function.
invokerIdentity — the identity to use that is present within the Caliper network configuration file.
This can be optional and caliper will select an identity for you (from the appropriate invoking organization or default organization)
readOnly — if performing a query operation or not.
Caliper Configuration (Optional) : For running test without long command,
we need to create one more file caliper.yaml inside the caliper folder.
Command : npx caliper launch manager --caliper-fabric-gateway-enabled