使用sysbench对腾讯云轻量数据库进行基准测试

最近腾讯云开启了轻量数据库的公测,经过博主的测试轻量数据的性能要远高于在自己云服务器上面自建的数据库,这里建议有条件或者有需求的可以使用

一、 安装sysbench

首先选择一台轻量数据库同区域的腾讯云轻量应用服务器,安装sysbench。

这个是数据库

数据库截图

这个是服务器

服务器截图

yum安装

wget https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh
chmod +x script.rpm.sh
./script.rpm.sh
yum install -y sysbench

下载tar.gz安装

yum install -y automake libtool
wget https://github.com/akopytov/sysbench/archive/refs/tags/1.0.20.tar.gz
tar zvxf 1.0.20.tar.gz
cd sysbench-1.0.20
./autogen.sh
./configure
make -j4
make install

二、准备测试表

新建用户和数据库


登录轻量数据库DMC,可以通过这里管理数据库的用户和库表,这里我新建了一个test-db

新建用户并授予对应库所有权限

CREATE USER `test`@`` IDENTIFIED BY 'test';

GRANT Alter, Alter Routine, Create, Create Routine, Create Temporary Tables, Create View, Delete, Drop, Event, Execute, Grant Option, Index, Insert, Lock Tables, References, Select, Show View, Trigger, Update ON `test\_db`.* TO `test`@``;


不知道怎么新建的测试也可以直接用root。

执行命令

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable prepare
sysbench 
//基于mysql的驱动去连接mysql数据库
--db-driver=mysql 
//连续访问300秒
--time=300 
//10个线程模拟并发访问
--threads=10 
//每隔1秒输出一下压测情况
--report-interval=1 
//本机
--mysql-host=127.0.0.1 
//端口号:3306
--mysql-port=3306 
//测试用户
--mysql-user=root 
//测试密码
--mysql-password=******* 
//测试数据库
--mysql-db=test_db 
//模拟新建20个表
--tables=20 
//100万条数据 执行oltp数据库的读写测试
--table_size=1000000 oltp_read_write 
//参照这个命令的设置去构造出来我们需要的数据库里的数据
//自动创建20个测试表,每个表里创建100万条测试数据
--db-ps-mode=disable prepare

命令执行之后:

三、开始测试

1、测试综合TPS

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable run

测试命令执行之后

反馈解释:thds 压测线程数 | tps 每秒事务数 | qps 每秒请求数 | (r/w/o) 每秒的请求数中读请求个数/写请求个数/其他请求个数 | lat(ms,95%) 95% 的请求延迟都在多少以下 | err/s 错误数 | reconn/s 重连数

测试结果:

SQL statistics:
    queries performed:
        read:                            1379084                       #300s执行了137万读请求
        write:                           394024                        #300s执行了39万写请求
        other:                           197012                        #300s执行了19万其他请求
        total:                           1970120                       #300s执行了共197万请求
    transactions:                        98506  (328.27 per sec.)      #300s执行了共9.8万次事务(每秒382.27次事务)
    queries:                             1970120 (6565.43 per sec.)    #300s执行了查询共197万次请求(每秒0.65万次请求)
    ignored errors:                      0      (0.00 per sec.)        #300s忽略错误总数(每秒忽略错误次数)
    reconnects:                          0      (0.00 per sec.)        #300s重连总数(每秒重连次数)

General statistics:
    total time:                          300.0742s                     #总耗时
    total number of events:              98506                         #总发生的事务数

Latency (ms):
         min:                                   20.68                  #最小延迟 20.68ms
         avg:                                   30.46                  #平均延迟 30.46ms
         max:                                  162.34                  #最大延迟 162.34ms
         95th percentile:                       46.63                  #95%的请求延迟 46.63ms
         sum:                              3000010.96

Threads fairness:
    events (avg/stddev):           9850.6000/536.53
    execution time (avg/stddev):   300.0011/0.03

2、其他测试

只读性能 oltp_read_only

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_only --db-ps-mode=disable run

删除性能 oltp_delete

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_delete --db-ps-mode=disable run

更新索引字段性能 oltp_update_index

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_update_index --db-ps-mode=disable run

更新非索引字段性能 oltp_update_non_index

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_update_non_index --db-ps-mode=disable run

插入性能 oltp_insert

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_insert --db-ps-mode=disable run

写入性能 oltp_write_only
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_write_only --db-ps-mode=disable run

测试完成进行清理 CleanUp

sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable cleanup

至此本次基准测试到此结束,使用sysbench对腾讯云轻量数据库进行基准测试有其他不明白的地方,朋友可以到我博客和我交流

博主站点

博主的个人博客地址是:https://www.hipyt.cn/

最后

安利一下,腾讯云限时秒的活动,优惠力度非常大,当前买到就是赚到了,1核2G的配置最低99元一年。

为了保证博主的写作兴趣,请大家有需要的一定要多多支持。以下连接内含(AFF)

【腾讯云】云产品限时秒杀,爆款1核2G云服务器,首年99元
腾讯云限时秒杀

【腾讯云】轻量应用服务器Lighthouse,上云「轻」而易举,1核1G3M低至128元/年,高带宽首选

image.png

期待下一次给大家带来更好的教程,我们下次再见。

最后修改:2021 年 09 月 03 日
如果觉得我的文章对你有用,请随意赞赏