Hyperledger caliper架构介绍和源码分析

Hyperledger Caliper是一个区块链性能测试框架,包括应用层、适配层和基准测试层。应用层提供测试用例,适配层集成不同区块链系统,基准测试层执行测试。配置文件如config.json和fabric.json定义测试参数和区块链网络配置。主流程涉及main.js和bench-flow.js,监控资源如CPU、内存和网络IO。Benchmark Engine负责测试流程,包括准备、测试和报告阶段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


简要分析caliper 的代码实现,以 benchmark/simple为例。
根据 caliper架构图
在这里插入图片描述

Application layer

应用程序层包含针对典型区块链方案实施的测试。 每个测试都有一个配置文件,用于定义后端区块链网络和测试参数。 这些测试可以直接用于测试区块链系统的性能。
开发人员可以直接使用NBI来实现自己的测试而不需要框架。

Adaptation layer

适配层主要作用是将现有的区块链系统集成到caliper框架中。每个适配器使用相应的区块链原生(native)SDK或RESTful API实现 ‘Caliper Blockchain NBI’。
现在支持Hyperledger Fabric1.0 和 Sawtooth,以太坊和其他的区块链系统仍在计划中。
src文件夹下为该项目的主要代码。
src/comm包内是Interface & Core Layer的代码;
src/fabricsrc/sawtoothsrc/iroha包内是Adaptation layer的具体代码。
在这里插入图片描述
fabric.js中的Fabric类就继承自BlockchainInterface,实现了初始化、安装/执行智能合约等功能。
这些功能内部自然就是调用了fabric-client,所以测试前需要先进行安装:

npm install grpc@1.10.1 fabric-ca-client fabric-client

Benchmark layer

测试用例位于benchmark/目录下, 由测试人员编写,并配置到-c指定的配置文件的test.rounds[.callback]中。
每个测试用例都包含定义了具体功能的.js文件(如main.jsquery.js)和两种配置文件(config.json和fabric.json)。如下为marbles示例:
在这里插入图片描述

Configuration file

使用两种配置文件:
config.json:benchmark配置文件,定义benchmark测试的参数,如测试轮次,工作负载等;
fabric.json:区块链配置文件,指定了与SUT(system under test)交互的必要信息,即区块链网络的配置,如peer数,client数等。

这两个配置文件很重要,caliper就是根据这两个配置文件的设置来进行测试的。

  • benchmark configuration file
    example:
{
   
  "blockchain": {
   
    "type": "fabric",
    "config": "./fabric.json"
  },
  "command" : {
   
    "start": "docker-compose -f ../../network/fabric/simplenetwork/docker-compose.yaml up -d",
    "end" : "docker-compose -f ../../network/fabric/simplenetwork/docker-compose.yaml down;docker rm $(docker ps -aq)"
  },
  "test": {
   
    "name": "simple",
    "description" : "This is an example benchmark for caliper",
    "clients": {
   
      "type": "local",
      "number": 5
    },
    "rounds": [{
   
        "label" : "open",
        "txNumber" : [5000, 5000, 5000],
        "rateControl" : [{
   "type": "fixed-rate", "opts": {
   "tps" : 100}}, {
   "type": "fixed-rate", "opts": {
   "tps" : 200}}, {
   "type": "fixed-rate", "opts": {
   "tps" : 300}}],
        "arguments": {
     "money": 10000 },
        "callback" : "benchmark/simple/open.js"
      },
      {
   
        "label" : "query",
        "txNumber" : [5000, 5000],
        "rateControl" : [{
   "type": "fixed-rate", "opts": {
   "tps" : 300}}, {
   "type": "fixed-rate", "opts": {
   "tps" : 400}}],
        "callback" : "benchmark/simple/query.js"
      }]
  },
  "monitor": {
   
    "type": ["docker", "process"],
    "docker":{
   
      "name": ["peer0.org1.example.com", "http://192.168.1.100:2375/orderer.example.com"]
    },
    "process": [
      {
   
        "command" : "node",
        "arguments" : "local-client.js",
        "multiOutput" : "avg"
      }
    ],
    "interval": 1
  }
}
  • Fabric Configuration file
    example
{
   
  "fabric": {
   
    "cryptodir": "network/fabric/simplenetwork/crypto-config",
    "network": {
   
      "orderer": {
   
        "url": "grpcs://localhost:7050",
        "mspid": "OrdererMSP",
        "domain": "example.com",
        "user"
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值