Warm tip: This article is reproduced from stackoverflow.com, please click
hyperledger hyperledger-fabric node.js performance

Hyperledger Fabric

发布于 2020-04-07 10:14:05

I'm trying to run a project using Hyperledger Fabric with a setup similar to the Fabcar example.

I'm surprised by the huge amount of time it takes to submit a transaction.

Just to make it simple and fully reproducible I measured the time needed submit the transaction createCar on the actual Fabcar project. After setting up the network (startFabric.sh javascript) and enrolling the admin and a user, I run the invoke.js script. The whole script takes about 2.5 seconds!

As far as I can understand running the contract takes just few milliseconds. The same for sending the Transaction Proposal. It mostly spend time having the eventHandler listening and waiting for the event (in the transaction.js library).

Is there a way of speeding up the process? I was expecting to be able to submit several transactions per second.

Questioner
marco
Viewed
75
Pierre-Henri Debris 2020-02-03 17:27

Short answer : decrease BatchTimeout in configtx.yaml

Long answer :

If you only run one query, like you describe, this is totaly normal.

If you look at your configtx.yaml, in the part 'Orderer', you can see this :

Orderer: &OrdererDefaults

# Orderer Type: The orderer implementation to start
# Available types are "solo" and "kafka"
OrdererType: solo

Addresses:
    - orderer.example.com:7050

# Batch Timeout: The amount of time to wait before creating a batch
BatchTimeout: 2s

# Batch Size: Controls the number of messages batched into a block
BatchSize:

    # Max Message Count: The maximum number of messages to permit in a batch
    MaxMessageCount: 10

    # Absolute Max Bytes: The absolute maximum number of bytes allowed for
    # the serialized messages in a batch.
    AbsoluteMaxBytes: 99 MB

    # Preferred Max Bytes: The preferred maximum number of bytes allowed for
    # the serialized messages in a batch. A message larger than the preferred
    # max bytes will result in a batch larger than preferred max bytes.
    PreferredMaxBytes: 512 KB

There are 2 important things :

  • BatchTimeout
  • MaxMessageCount

BatchTimeout define the maximum time before creating a block. This mean, when an invoke is made, the orderer compute the transaction and wait for 2 seconds before creating the block. This mean, each first transaction will take more than 2 seconds ! But if there is another invoke, lets say, at 1,5s after the first transaction, the second call will take less than 1s !

MaxMessageCount, speak for itself. It mean that if there are more than 10 invoke, a block will be created, even if the 2 seconds are not past. For example, 10 invoke in a row of 0.5s will result in a block creation in less than a second.

This settings are here to balance the load depending on your network. Let's say you have a low use application, with less than 10 tps (transaction per second), you can reduce the BatchTimeout to less than 2s to increased response time of invoke. If you have a hight tps, you can increased the MaxMessageCount to create larger block.

The others settings define the max size of a message.

Try to know how your network will be, simulate the estimated tps with a test case and tweak the parameters to find the configuration of your needs.