首页 > 数据库 > 数据库开发技术 > 国产数据库能否扛住压力—HaloDB压力测试
作者:Digital Observer(施嘉伟)
Oracle ACE Pro: Database
PostgreSQL ACE Partner
11年数据库行业经验,现主要从事数据库服务工作
拥有Oracle OCM、DB2 10.1 Fundamentals、MySQL 8.0 OCP、WebLogic 12c OCA、KCP、PCTP、PCSD、OCI、PolarDB技术专家、达梦师资认证、数据安全咨询高级等认证
ITPUB认证专家、PolarDB开源社区技术顾问、HaloDB技术顾问、TiDB社区技术布道师、青学会MOP技术社区专家顾问、国内某高校企业实践指导教师
公众号:Digital Observer;CSDN:施嘉伟;ITPUB:sjw1933;PGFans:施嘉伟。
众所周知国产化数据库进行压力测试的方法是通过模拟大量并发用户和操作,使用工具如JMeter或sysbench进行性能和负载测试,以评估数据库在高负荷下的稳定性和响应能力。本期我们来尝试用Sysbench压下HaloDB。
Sysbench 是一个开源软件工具,具体来说,它是一个为 Linux 系统设计的可脚本多线程基准工具。它是一个 C 二进制文件,使用 LuaJIT 脚本来执行基准。它最常用于数据库基准测试,例如 PostgreSQL,但也可用于创建不涉及数据库服务器的一般性能测试。
安装包下载地址:https://github.com/akopytov/sysbench/tags
操作系统版本:CentOS Linux release 7.9.2009 (Core)
# tar -zxvf sysbench-1.0.20.tar.gz
# cd sysbench-1.0.20/
# ./autogen.sh
# ./configure --without-mysql --with-pgsql --with-pgsql-includes=/u01/app/halo/product/dbms/14/include --with-pgsql-libs=/u01/app/halo/product/dbms/14/lib
# make
# make install
这里会碰到两个报错:
报错:
[18:19:43][root@mysql3 ~]# cd sysbench-1.0.20/
[18:19:49][root@mysql3 sysbench-1.0.20]# ./autogen.sh
[18:19:49]automake 1.10.x (aclocal) wasn't found, exiting
解决方法:
[18:25:58][root@mysql3 sysbench-1.0.20]# yum install automake
[18:26:02]Loaded plugins: fastestmirror
[18:26:02]Loading mirror speeds from cached hostfile
报错:
[root@mysql3 sysbench-1.0.20]# ./autogen.sh
libtoolize 1.4+ wasn't found, exiting
解决方法:
[root@mysql3 sysbench-1.0.20]# yum -y install libtool
# su - halo
$ sysbench --version如果遇下面报错:
sysbench: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory
解决方法:
# vi .bash_profile
添加以下内容
export LD_LIBRARY_PATH=/u01/app/halo/product/dbms/14/lib
# source .bash_profile
# sysbench --version
参数填写Halodb数据库相关信息,注意threads(线程)数。测试数据生成一次即可。
[root@mysql3 ~]# sysbench /usr/local/share/sysbench/oltp_read_write.lua --auto_inc=off --pgsql-host=127.0.0.1 --pgsql-port=1921 --pgsql-db=test --table_size=500000 --tables=20 --threads=20 --time=60 --report-interval=10 --pgsql-user=halo --pgsql-password=halotest --db-driver=pgsql prepare
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Initializing worker threads...
Creating table 'sbtest7'...
Creating table 'sbtest17'...
Creating table 'sbtest13'...
Creating table 'sbtest9'...
Creating table 'sbtest4'...
Creating table 'sbtest6'...
Creating table 'sbtest19'...
Creating table 'sbtest16'...
Creating table 'sbtest20'...
Creating table 'sbtest3'...
Creating table 'sbtest12'...
Creating table 'sbtest5'...
Creating table 'sbtest14'...
Creating table 'sbtest11'...
Creating table 'sbtest18'...
Creating table 'sbtest10'...
Creating table 'sbtest8'...
Creating table 'sbtest1'...
Creating table 'sbtest15'...
Creating table 'sbtest2'...
Inserting 500000 records into 'sbtest14'
Inserting 500000 records into 'sbtest19'
Inserting 500000 records into 'sbtest12'
Inserting 500000 records into 'sbtest17'
Inserting 500000 records into 'sbtest6'
Inserting 500000 records into 'sbtest15'
Inserting 500000 records into 'sbtest7'
Inserting 500000 records into 'sbtest2'
Inserting 500000 records into 'sbtest8'
Inserting 500000 records into 'sbtest11'
Inserting 500000 records into 'sbtest3'
Inserting 500000 records into 'sbtest9'
Inserting 500000 records into 'sbtest1'
Inserting 500000 records into 'sbtest16'
Inserting 500000 records into 'sbtest5'
Inserting 500000 records into 'sbtest18'
Inserting 500000 records into 'sbtest10'
Inserting 500000 records into 'sbtest4'
Inserting 500000 records into 'sbtest13'
Inserting 500000 records into 'sbtest20'
Creating a secondary index on 'sbtest1'...
Creating a secondary index on 'sbtest20'...
Creating a secondary index on 'sbtest18'...
Creating a secondary index on 'sbtest13'...
Creating a secondary index on 'sbtest8'...
Creating a secondary index on 'sbtest19'...
Creating a secondary index on 'sbtest4'...
Creating a secondary index on 'sbtest12'...
Creating a secondary index on 'sbtest2'...
Creating a secondary index on 'sbtest3'...
Creating a secondary index on 'sbtest9'...
Creating a secondary index on 'sbtest5'...
Creating a secondary index on 'sbtest11'...
Creating a secondary index on 'sbtest7'...
Creating a secondary index on 'sbtest15'...
Creating a secondary index on 'sbtest16'...
Creating a secondary index on 'sbtest14'...
Creating a secondary index on 'sbtest10'...
Creating a secondary index on 'sbtest6'...
Creating a secondary index on 'sbtest17'...
参数名 |
说明 |
--db-driver |
指定要测试的数据库类型, |
--pgsql-host |
数据库机器的 IP |
--pgsql-port |
端口号 |
--pgsql-user |
用户名 |
--pgsql-password |
密码 |
--pgsql-db |
待连接的数据库 |
--table_size |
每张表初始化的数据数量 |
--tables |
初始化表的数量 |
--threads |
启动的线程数量。 |
--time |
运行时间 |
--report-interval |
指定间隔定期报告 |
--auto_inc |
是否启用自增主键,设为off使用随机主键 |
oltp_read_write |
在 Sysbench目录下,自带有针对不同场景的测试用例,有oltp_read_write、oltp_read_only、oltp_write_only |
threads(线程)数分别设为2、4、8、16、32...... 测试到出现峰值
[root@mysql3 ~]# sysbench /usr/local/share/sysbench/oltp_read_write.lua --auto_inc=off --pgsql-host=127.0.0.1 --pgsql-port=1921 --pgsql-db=test --table_size=500000 --tables=20 --threads=2 --time=60 --report-interval=10 --pgsql-user=halo --pgsql-password=halotest --db-driver=pgsql run
记录QPS(每秒查询)和TPS(每秒事务),只读和只写都记录。

hreads(线程)数分别设为2、4、8、16、32...... 测试到出现峰值
[root@mysql3 ~]# sysbench /usr/local/share/sysbench/oltp_read_only.lua --auto_inc=off --pgsql-host=127.0.0.1 --pgsql-port=1921 --pgsql-db=test --table_size=500000 --tables=20 --threads=2 --time=60 --report-interval=10 --pgsql-user=halo --pgsql-password=halotest --db-driver=pgsql run
threads(线程)数分别设为2、4、8、16、32...... 测试到出现峰值
[root@mysql3 ~]# sysbench /usr/local/share/sysbench/oltp_write_only.lua --auto_inc=off --pgsql-host=127.0.0.1 --pgsql-port=1921 --pgsql-db=test --table_size=500000 --tables=20 --threads=2 --time=60 --report-interval=10 --pgsql-user=halo --pgsql-password=halotest --db-driver=pgsql run

由于不同服务器、操作系统和软件版本的差异,压力测试的结果会有所不同。本次文档提供了通过 Sysbench 对数据库进行压力测试的方法,大家可以参考并测试自己的预生产数据库是否符合业务需求。
最后祝HaloDB越来越好!
往期推荐:


原文作者:Digital Observer;如有侵权,请联系管理员删除。