> For the complete documentation index, see [llms.txt](https://boohyung.gitbook.io/tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boohyung.gitbook.io/tech/development/hyperledger-caliper.md).

# Hyperledger Caliper Sample(caliper-benchmarks)

source: Installing and Running Caliper(https\://hyperledger.github.io/caliper/vLatest/installing-caliper)

## Notice

2020-03-04: Caliper v0.3.0 Released

{% hint style="info" %}
Change log: <https://github.com/hyperledger/caliper/blob/master/CHANGELOG.md>
{% endhint %}

## Environment

* Ubuntu 18.04 LTS
* Hyperledger Caliper v0.3.0

## Caliper 설치

```bash
git clone https://github.com/hyperledger/caliper.git

cd caliper

# Installs development-time dependencies, such as Lerna and the license checking package
npm install

# @hyperledger/caliper-cli NPM Package dependency 전역으로 설치
npm install -g --only=prod @hyperledger/caliper-cli
```

## **Caliper Sample(caliper-benchmarks) 설치 및 실행**

```bash
git clone https://github.com/hyperledger/caliper-benchmarks.git

cd caliper-benchmarks

# package.json(해당 node 프로그램에 대한 기본 정보를 담고 있음) 생성
npm init -y

# @hyperledger/caliper-cli NPM Package dependency 설치
npm install --only=prod \
    @hyperledger/caliper-cli@0.2.0

# npx로 설치없이 local CLI package를 1회성으로 실행: @hyperledger/1.4.0을 현재 폴더에 바인딩
npx caliper bind \
    --caliper-bind-sut fabric:1.4.0

# caliper benchmark run -w  -c  -n  
## -w : workspace 디렉토리 경로 (필수) 
## -c : workspace에서 벤치마크 configuration 파일 상대경로 (필수) 
## -n : workspace에서 테스트할 블록체인 네트워크 config 파일의 상대경로
npx caliper launch master \
    --caliper-workspace . \
    --caliper-benchconfig benchmarks/scenario/simple/config.yaml \
    --caliper-networkconfig networks/fabric/fabric-v1.4.1/2org1peergoleveldb/fabric-go.yaml
```

v0.3.0부터는 launch command로 test를 실행한다. (v0.2.0까지는은 benchamark run command 사용)

### Caliper Sample Test 절차 설명

1. docker network "2org1peergoleveldb\_default" 생성
2. orderer, ca.org1, ca.org2, peer0.org1, peer0.org2 컨테이너생성
3. client 및 보증 정책 설정
   * OrgMSP1: User, Admin
   * OrgMSP2: User
4. 채널 "mychannel" 생성 후 채널에 peer 참여
5. 각 peer에 시나리오 별 체인코드 설치: @marble, @drm, @simple, @smallbank
6. 설치한 체인코드 인스턴스화, Simple 시나리오로 테스트 시작
   * 'open' test: 테스트 결과와 함께 docker resource 출력
   * 'query' test: 테스트 결과와 함께 docker resource 출력
   * 'transfer' test: 테스트 결과와 함께 docker resource 출력
7. 3개 함수 호출 테스트 결과 출력
   * 성공/실패 트랜잭션 개수
     * 트랜잭션 개수는 config.yaml에서 설정 가능
   * Latency(Max/Min/Avg): 초 단위 지연 시간
   * Throughput(TPS)
8. html 형식의 보고서 생성(위치: /caliper-benchmarks/report.html)
9. 실행 중이던 컨테이너 중지 및 삭제

![Caliper report(example)](https://2837883091-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LL3wrd9YkzoOQE1asZU%2F-M39S4Dq-d-agBjWIjtO%2F-M39SPWtgWYyzzbbBNDy%2F20200324_115327.png?alt=media\&token=14683c33-4d74-4ec7-b74a-b820a93228ae)

### Troubleshooting

Error: Table must define at least one row.(<https://github.com/hyperledger/caliper/issues/670>)

* Solution: config.yaml 수정 후 다시 실행(path: caliper-benchmarks/benchmarks/scenario/simple/config.yaml)
  * (from) txNumber: 100
  * (to) txNumber:
    * 100

Error: Invalid endorsement for marbles\@v0 in mychannel from peer0.org1.example.com

* Solution: pull the hyperledger/fabric-ccenv docker image (<https://hub.docker.com/r/hyperledger/fabric-ccenv>)

  docker pull hyperledger/fabric-ccenv

## Reference

<https://medium.com/@kotsbtechcdac/tool-to-measure-blockchain-performance-hyperledger-caliper-f192adfba52>
