区块链 使用xbench测试xuperchain 教程

本文详细介绍了如何在多机环境下安装Xuperchain,并通过xbench进行交易性能测试,包括单机单节点部署步骤、xbench的多种测试类型和案例,以及处理合同调用和查询的技巧。还分享了常见错误处理和解决方法,适合开发者深入了解区块链性能评估。

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

一、安装xuperchain

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

1.单机单节点

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

2.多机多节点部署

https://shijianfeng.blog.csdn.net/article/details/117305713

二、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 counterand 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

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


四、测试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内存单节点测得

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

软件工程小施同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值