我正在尝试使用Hyperledger Fabric和类似于Fabcar示例的设置运行项目。
我对提交交易需要花费大量时间感到惊讶。
为了简单和完全可复制,我测量createCar
了实际Fabcar项目上提交交易所需的时间。设置网络(startFabric.sh
javascript)并注册管理员和用户后,我运行invoke.js
脚本。整个脚本大约需要2.5秒!
据我了解,运行合同仅需几毫秒。发送交易建议也是如此。它主要花费时间让eventHandler监听并等待事件(在transaction.js
库中)。
有没有加快流程的方法?我期望每秒能够提交几笔交易。
简短答案:减少configtx.yaml中的BatchTimeout
长答案:
如果您只运行一个查询(如您描述的那样),那是完全正常的。
如果您查看configtx.yaml,则在“订购者”部分中可以看到:
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
有两件重要的事情:
BatchTimeout定义创建块之前的最长时间。这意味着,在进行调用时,订购者将计算事务并等待2秒,然后再创建该块。这意味着,每个第一次交易将花费2秒钟以上!但是,如果有另一个调用,可以说,在第一次事务处理后1.5秒,第二次调用将花费不到1秒!
MaxMessageCount,不言而喻。这意味着,如果调用超过10次,即使2秒未过去,也会创建一个块。例如,连续0.5秒执行10次调用将在不到一秒钟的时间内创建一个块。
此设置用于根据网络平衡负载。假设您有一个使用率较低的应用程序,其每秒传输量小于10 tps(事务每秒),则可以将BatchTimeout减少到小于2s,以增加调用的响应时间。如果您的tps高,则可以增加MaxMessageCount来创建更大的块。
其他设置定义邮件的最大大小。
尝试了解您的网络状况,使用测试用例模拟估计的tps,并调整参数以找到所需的配置。