Fabric hyperledger learning [3] Fabric2.4 uses Tape for throughput performance testing

If you want to test the execution time of a certain contract function by Hyperledger Fabric, you can simply calculate the time difference by printing the contract function start execution time and end execution time.

Tape is a lightweight Hyperledger Fabric performance testing tool.

The github address of tape: https://github.com/Hyperledger-TWGC/tape

step:

  1. Start the Fabric2.4 network environment, install and deploy the official chain code (asset) (successfully build the Fabric2.x network is the prerequisite)
./network.sh up createChannel -s couchdb

Note that there must be couchdb, otherwise it will be unsuccessful! ! ! ! ! ! ! !insert image description here

  1. Clone the official tape repository: git clone https://github.com/Hyperledger-TWGC/tape

insert image description here

  1. Copy the certificate folder generated by the network of test-network into the tape file:

insert image description here

  1. Enter the Tape folder, find the config.yaml file, and modify the configuration information as follows:
    insert image description here
    Replace the configuration information of the config.yaml file with the following configuration information
# Definition of nodes
peer1: &peer1
  addr: localhost:7051
  ssl_target_name_override: peer0.org1.example.com
  org: org1
  tls_ca_cert: /config/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem
 
peer2: &peer2
  addr: localhost:9051
  ssl_target_name_override: peer0.org2.example.com
  org: org2
  tls_ca_cert: /config/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/tlscacerts/tlsca.org2.example.com-cert.pem
 
orderer1: &orderer1
  addr: localhost:7050
  ssl_target_name_override: orderer.example.com
  org: org1
  tls_ca_cert: /config/organizations/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem
 
policyFile: /config/test/andLogic.rego
 
# Nodes to interact with
endorsers:
  - *peer1
# we might support multi-committer in the future for more complex test scenario,
# i.e. consider tx committed only if it's done on >50% of nodes. But for now,
# it seems sufficient to support single committer.
committers: 
  - *peer1
  - *peer2
 
commitThreshold: 1
 
orderer: *orderer1
 
# Invocation configs
channel: mychannel
chaincode: basic
args:
  - GetAllAssets
mspid: Org1MSP
private_key: /config/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/priv_sk
sign_cert: /config/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]-cert.pem
num_of_conn: 10
client_per_conn: 10
  1. Then enter the following command in the command line under the tape folder to start the execution. The screenshot of the successful operation is as follows:
docker run --network=host -v $PWD:/config guoger/tape tape -c /config/config.yaml -n 50000

insert image description here
The meaning of the parameters is as follows:

Time: time-consuming

Block: block height

tx: number of transactions

duration: total time-consuming

tps: number of transactions per second (TPS = number of transactions / total transaction time)

If you want to run the specified contract function 1000 times, you can run the following command:

./tape --config=config.yaml --number=1000
./tape -c config.yaml -n 1000

The above command is to directly run the specified contract function 1000 times, so the transaction volume may be too large in an instant, and the blockchain cannot handle it, resulting in transaction loss. Tape has two parameters –rate and –brust, which use the token bucket mechanism to implement current limiting.

The burst parameter is an integer that defines the size of the token bucket,

The rate parameter is a floating-point number, which defines the number of tokens added to the token bucket per second (note that rate can be a decimal, such as rate is 0.2, which means that 0.2 tokens are added to the token bucket per second), 0 means no limit

The rate parameter cannot be greater than burst, otherwise, the size of rate is set to the size of burst

./tape -c config.yaml -n 1000 --rate=0.2 --burst=1 means that the initial value of the token in the token bucket is 1, and the contract function is executed once at the beginning (every time the contract function is executed, let The number of cards minus 1), the remaining number of tokens in the token bucket becomes 0. The next step is to add 0.2 tokens per second. At the 5th second, the number of tokens in the token bucket is 1, then execute the contract function once again, and the remaining number of tokens in the token bucket becomes 0 again, and so on analogy.

./tape -c config.yaml -n 1000 --rate=0.2 --burst=2 means that the initial value of tokens in the token bucket is 2, and the contract function is executed twice at the beginning, and the remaining tokens in the token bucket number becomes 0. The next step is to add 0.2 tokens per second. At the 5th second, the number of tokens in the token bucket is 1, then execute the contract function once again, and the remaining number of tokens in the token bucket becomes 0 again, and so on analogy.

Assuming that the Test function is only run twice, execute the command: . /tape -c config.yaml -n 2, we can see the running result:

Time 2.15s Block 1049 Tx 2

tx: 2, duration: 2.146063431s, tps: 0.931939

The above results indicate that:

The total time is about 2.146063431 seconds, the block number of the transaction is 1049, the number of transactions is 2, and the TPS (transactions per second) is 0.931939 (TPS = number of transactions / total transaction time)

Through the Tape tool, you can implement the stress test of Fabric on a specified contract function, and get the corresponding TPS test results

Guess you like

Origin blog.csdn.net/weixin_42694422/article/details/129444076