Caliper 圧力テストツール (ローカルテスト)#
1. nodejs のインストール#
-
nvm またはシステムに付属のパッケージマネージャー(apt または yum)を使用してインストール
-
nodejs バージョン => 8
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash または wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash 実行 export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # 環境変数を追加
2. Docker のデプロイ#
-
docker バージョン >= 18.06.01
-
インストールガイド:
実行
apt install docker.io または yum install docker
3. Caliper のデプロイ#
-
新しい作業ディレクトリを作成
mkdir benchmarks && cd benchmarks
-
npm プロジェクトを初期化
npm init
-
caliper-cli
をインストールnpm install --only=prod @hyperledger/[email protected]
-
インストールが成功したかテスト
npx caliper --version
-
ブロックチェーンプラットフォームをバインド
-
Caliper は軽量なデプロイ方式を採用しているため、テストするプラットフォームとアダプターバージョンを明示的に指定する必要があります。
caliper-cli
は自動的に必要な依存関係をインストールします。npx caliper bind
コマンドを使用してバインドし、コマンドに必要な各パラメータは以下のコマンドで確認できます:user@ubuntu:~/benchmarks$ npx caliper bind --help 使用法: caliper bind --caliper-bind-sut fabric --caliper-bind-sdk 1.4.1 --caliper-bind-cwd ./ --caliper-bind-args="-g" オプション: --help ヘルプを表示 [boolean] -v, --version バージョン番号を表示 [boolean] --caliper-bind-sut バインドするプラットフォームの名前 [string] --caliper-bind-sdk バインドするプラットフォームSDKのバージョン [string] --caliper-bind-cwd SDKインストールを実行する作業ディレクトリ [string] --caliper-bind-args "npm install"に渡す追加の引数。パラメータを設定する際は"="表記を使用 [string]
-
-
FISCO BCOS の場合、以下の方法でバインドできます:
npx caliper bind --caliper-bind-sut fisco-bcos --caliper-bind-sdk latest
3. FISCO BCOS ベンチマークテストの迅速な体験#
-
作業ディレクトリで事前定義されたテストケースをダウンロード
git clone https://github.com/vita-dounai/caliper-benchmarks.git または git clone https://gitee.com/mirrors_hyperledger/caliper-benchmarks.git
CentOS システムでは selinux を無効にする必要があります
4. 設定の変更#
-
/benchmarks/node_modules/\@hyperledger/caliper-fisco-bcos/lib/channelPromise.js
の 49 行目を次のように変更:let emitter = emitters.get(seq); if(!emitter) { //古いメッセージを受信 return; } emitter = emitter.emitter;
-
/benchmarks/node_modules/\@hyperledger/caliper-fisco-bcos/lib/fiscoBcos.js
の 25 行目を次のように変更:const Color = require('./common').Color;
-
/benchmarks/node_modules/\@hyperledger/caliper-fisco-bcos/lib/web3lib/web3sync.js
の 27 行目、91 行目、118 行目をそれぞれ次のように変更:27 行目:
uuid = '0x' + uuid.replace(/-/g, '');
91 行目
extraData: '0x0'
118 行目
extraData: '0x0'
-
/benchmarks/node_modules/\@hyperledger/caliper-fisco-bcosのpackage.json
ファイルを変更し、dependencies
フィールドにsecp256k1": "^3.8.0
を追加し、その後このディレクトリでnpm i
を実行 -
/benchmarks/caliper-benchmarks/networks/fisco-bcos/4nodes1group/fisco-bcos.json
を変更し、command
フィールドを削除 -
authentication
フィールド内のkey
,cert
,ca
フィールドのパスをficso/nodes/127.0.0.1/sdk/
ディレクトリ内の対応するファイルの位置に変更 -
nodes
フィールド内のrpcport
とchannelport
をローカルチェーンポートに変更 -
/benchmarks/caliper-benchmarks/benchmarks/samples/fisco-bcos/helloworld/config.yaml
の末尾に次を追加:monitor: type: - process process: - command: node0 arguments: fiscoBcosClientWorker.js multiOutput: avg - command: node1 arguments: fiscoBcosClientWorker.js multiOutput: avg - command: node2 arguments: fiscoBcosClientWorker.js multiOutput: avg - command: node3 arguments: fiscoBcosClientWorker.js multiOutput: avg interval: 0.5
以下の内容は helloworld の例です#
-
/benchmarks/caliper-benchmarks/benchmarks/samples/fisco-bcos/helloworld/
ディレクトリ内のget.js
とset.js
を変更get.js
/* * Apache License, Version 2.0 (the "License")の下でライセンスされています。 * あなたはライセンスに従ってこのファイルを使用することができます。 * ライセンスのコピーは以下から入手できます。 * * http://www.apache.org/licenses/LICENSE-2.0 * * 適用法に従っている限り、または書面で合意されている限り、ソフトウェアは * "現状のまま"提供され、いかなる種類の保証や条件もありません。 * ライセンスに従って権利と制限が適用されます。 */ 'use strict'; module.exports.info = ' 名前を照会中'; let bc, contx; module.exports.init = function (blockchain, context, args) { // 何もしない bc = blockchain; contx = context; return Promise.resolve(); }; module.exports.run = function () { return bc.queryState(contx, 'helloworld', 'v0', null, 'get()'); }; module.exports.end = function () { // 何もしない return Promise.resolve(); };
set.js
/* * Apache License, Version 2.0 (the "License")の下でライセンスされています。 * あなたはライセンスに従ってこのファイルを使用することができます。 * ライセンスのコピーは以下から入手できます。 * * http://www.apache.org/licenses/LICENSE-2.0 * * 適用法に従っている限り、または書面で合意されている限り、ソフトウェアは * "現状のまま"提供され、いかなる種類の保証や条件もありません。 * ライセンスに従って権利と制限が適用されます。 */ 'use strict'; module.exports.info = ' 名前を設定中'; let bc, contx; let txnPerBatch; module.exports.init = function (blockchain, context, args) { txnPerBatch = 1; bc = blockchain; contx = context; return Promise.resolve(); }; /** * シンプルなワークロードを生成します * @return {Object} jsonオブジェクトの配列 */ function generateWorkload() { let workload = []; for (let i = 0; i < txnPerBatch; i++) { let w = { 'transaction_type': 'set(string)', 'name': 'こんにちは! - ' + process.pid.toString() + 'から', }; workload.push(w); } return workload; } module.exports.run = function () { let args = generateWorkload(); return bc.invokeSmartContract(contx, 'helloworld', 'v0', args, null); }; module.exports.end = function () { // 何もしない return Promise.resolve(); };
5. helloworld テストの実行(benchmarks フォルダ内で実行)#
npx caliper benchmark run --caliper-workspace caliper-benchmarks --caliper-benchconfig benchmarks/samples/fisco-bcos/helloworld/config.yaml --caliper-networkconfig networks/fisco-bcos/4nodes1group/fisco-bcos.json
パラメータの説明:
--caliper-workspace
作業ディレクトリを指定
--caliper-benchconfig
テスト設定ファイルを指定
--caliper-networkconfig
ネットワーク設定ファイルを指定
この記事の参考文献:
https://fisco-bcos-documentation.readthedocs.io/zh_CN/dev/docs/tutorial/caliper.html