一、安装xuperchain

下面2选1,本文选择多机多节点

1.单机单节点

​https://xuper.baidu.com/n/xuperdoc/quickstart.html​

2.多机多节点部署

二、xbench

1. 下载

# mkdir -p ~/xuper
cd ~/xuper


git clone https://github.com/xuperchain/xbench.git
cd ./xbench
make

2. 测试类型

Xbench 现在提供 10 种测试用例

  • deal​: Test postTx performance in transfer. Default prepare enough TXs and sign them.
  • generate​: Test account transfer performance.Default create enough accounts, transfer 1 from these accounts to one test account.
  • relay​: Test account transfer performance. Default create enough accounts, transfer 1 to themselves using the last txid, which do not need to selectUTXO.
  • query​: Test contract query performance. Default deploy​​counter​​​and invoke​​increase​​ method to increase key, query this key to test.
  • invoke​: Test contract invoke performance. Default deploy​​counter​​​,invoke​​increase​​ method to test
  • querytx​: Test tx query performace. Query the previous reftxid, query the first one if reach the end.
  • queryblock​: Test block query performance. Query the previous pre block, query the first one if reach the end.
  • queryacct​: Test account balance query performance. Default transfer n to an account,
  • lcvtrans​: Test transfer performnce using sdk. Should deploy endorser.
  • lcvinvoke​: Test contract invoke perfromace using sdk. Also should deploy endorser.

三、测试非contract invoke 或者 contract query

以local模式,​deal测试用例为例

1. 修改配置文件

cd ~/xuper/xbench/output/conf

区块链 使用xbench测试xuperchain 教程_xbench

config meanings:

  • gen.conf : profiling normal transfer process
  • deal.conf : prepare transaction data before, profiling postTx process
  • invoke.conf : profiling contract invoke process

下面以修改deal.json为例

vim deal.json
{
//tested block chain type(xchain/fabric)
"type": "xchain",
//concurrent num of transaction
"workNum": 10,
//working mode (local/remote)
"mode": "local",
//chain code name
"chain": "xuper",
//Encryption plugins(default/schnorr)
"crypto": "default",
//tested block chain ip:port
"host": "192.168.92.129:37101",
//test behaviors (deal/generate/invoke/query/...)
"rounds": [
{
//test cases
"label": "deal",
//requests of every worker
"number": [ 20 ]
}
]
}

2. 运行测试

cd ~/xuper/xbench/output
./bin/xbench -c ./conf/deal.json

区块链 使用xbench测试xuperchain 教程_xbench_02

区块链 使用xbench测试xuperchain 教程_2d_03

四、测试contract invoke 或者 contract query

编辑./conf/invoke.json

{
"type": "xchain",
"workNum": 500,
"mode": "local",
"chain": "xuper",
"crypto": "default",
"host": "192.168.92.135:37101",
"nodes": ["192.168.92.135:37101"],
"rounds": [
{
"label": "invoke",
"number": [ 1000 ]
}
]
}

在16核8G内存单节点测得

区块链 使用xbench测试xuperchain 教程_github_04

4核8G内存单节点,每次都是测得1300tps,

​https://github.com/xuperchain/xbench​

五、报错

1. 句柄数超出了系统限制

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1234d40]

goroutine 5273 [running]:
github.com/xuperchain/xuperbench/adapter/xchain/cases.Invoke.Run(0x148c2ea, 0x6, 0x148bc06, 0x6, 0x2dc, 0xc008db7c00, 0x2, 0x2, 0xc008cfbd80, 0xc008cfbd80)
/home/shijianfeng/xuper/xbench/adapter/xchain/cases/invoke.go:60 +0x140
github.com/xuperchain/xuperbench/benchmark.Worker.func2(0x2dc)
/home/shijianfeng/xuper/xbench/benchmark/client.go:24 +0x132
github.com/xuperchain/xuperbench/benchmark.Worker(0xc000560c48, 0x6, 0xc000560c68, 0x6, 0x14, 0x0, 0x3e8, 0x16f8c20, 0xc000564480, 0xc0001369a0, ...)
/home/shijianfeng/xuper/xbench/benchmark/client.go:51 +0x22d
created by github.com/xuperchain/xuperbench/benchmark.BenchRun
/home/shijianfeng/xuper/xbench/benchmark/master.go:52 +0x198

ulimit -a | grep 'open files'

临时修改:ulimit -n 65535

永久修改:echo  '* - nofile 65535' >> /etc/security/limits.conf

如果报错sudo: ulimit: command not found

则使用​​sudo​​​ ​​sh -c ​​​​"ulimit -n 65535 && exec su $LOGNAME"​

参考文档

​https://github.com/xuperchain/xbench​