微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

使用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/

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

原文地址:https://cloud.tencent.com/developer/article/1868418

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐