怎么使用Sysbench对滴滴云MySQL进行基准测试

这篇文章给大家介绍怎么使用Sysbench对滴滴云MySQL进行基准测试,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

Sysbench是一款开源的多线程、跨平台的基准测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。这里使用Sysbench针对滴滴云的MySQL进行基准测试。

使用的MySQL数据库为一台4G内存,50G存储容量的滴滴云MySQL数据库,由于滴滴云MySQL默认不能通过公网访问,此数据库通过一台滴滴云虚拟机(DC2)连接,滴滴云MySQL的使用可以参考以下链接,此处不再赘述。

https://help.didiyun.com/hc/kb/article/1143410/

其中关键的一步是为了云主机可以正常访问MySQL,需要创建用户,此处为方便测试,建议创建高权限账号。 怎么使用Sysbench对滴滴云MySQL进行基准测试 常用的基准测试指标包括

TPS/QPS:衡量吞吐量。

响应时间:包括平均响应时间、最小响应时间、最大响应时间、时间百分比等,其中时间百分比参考意义较大,如前95%的请求的最大响应时间。

并发量:同时处理的查询请求的数量。

1.在云主机上安装MySQL5.7客户端:

[root@dc2-user]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
[root@dc2-user]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
[root@dc2-user]# yum install mysql-community-client

2. 在云主机上安装sysbench

不同版本的sysbench语法有一定差别,本文使用的版本是sysbench2.0。

下载解压:

[root@dc2-user]# wget https://github.com/akopytov/sysbench/archive/1.0.zip -O "sysbench-1.0.zip"
[root@dc2-user]# unzip sysbench-1.0.zip
[root@dc2-user]# cd sysbench-1.0

安装依赖:

[root@dc2-user]# yum install automake libtool mysql-devel –y

安装,确认当前目录为sysbench目录。

[root@dc2-user]# ./autogen.sh
[root@dc2-user]# ./configure
[root@dc2-user]# make && make install

默认sysbench命令在这个路径下,/usr/local/bin/sysbench,如果未添加/usr/local/bin为环境变量,为方便使用,可以为sysbench命令添加软链。

[root@dc2-user]# ln -s  /usr/local/bin/sysbench /usr/bin/sysbench

验证命令可用性:

[root@dc2-user]#sysbench --version
sysbench 1.0.20

3. Sysbench命令用法

使用sysbench --help查看sysbench的命令用法,此处只介绍本文用到的一些命令选项和参数。

[root@dc2-user]# sysbench --help
Usage:
  sysbench [options]... [testname] [command]

本例中用到的[options]参数如下: --mysql-host:MySQL服务器主机名,默认localhost;如果在本机上使用localhost报错,提示无法连接MySQL服务器,改成本机的IP地址应该就可以了。 --mysql-port:MySQL服务器端口,默认3306 --mysql-user:用户名 --mysql-password:MySQL服务器密码 --oltp-test-mode:执行模式,包括simple、nontrx和complex,默认是complex。simple模式下只测试简单的查询;nontrx不仅测试查询,还测试插入更新等,但是不使用事务;complex模式下测试最全面,会测试增删改查,而且会使用事务,本例使用complex。 --oltp-tables-count:测试的表数量,本例选择10张表。 --oltp-table-size:测试的表的大小,本例选择100000条数据。 --threads:客户端的并发连接数,本例选用10。 --time:测试执行的时间,单位是秒,本例选择120秒。 --report-interval:生成报告的时间间隔,单位是秒,本例选择10秒。

[testname]指定用什么lua脚本进行测试,可以是自己编写的,也可以用sysbench自带的,自带脚本位于解压后的sysbench目录中tests/include/oltp_legacy下,本例使用oltp.lua脚本,可以模拟并发、建表、插入数据、删除数据等常规OLTP操作。 [command]选项包括prepare、run和cleanup,即数据准备、测试执行和测试后数据清理。

4. 测试举例

首先在滴滴云页面创建sbtest数据库。

怎么使用Sysbench对滴滴云MySQL进行基准测试

(1)准备数据

[root@dc2-user]# sysbench /home/dc2-user/sysbench-1.0/tests/include/oltp_legacy/oltp.lua --mysql-host=10.254.170.17 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 prepare

sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Creating table 'sbtest1'...
Inserting 100000 records into 'sbtest1'
Creating secondary indexes on 'sbtest1'...
Creating table 'sbtest2'...
Inserting 100000 records into 'sbtest2'
Creating secondary indexes on 'sbtest2'...
Creating table 'sbtest3'...
Inserting 100000 records into 'sbtest3'
Creating secondary indexes on 'sbtest3'...
Creating table 'sbtest4'...
Inserting 100000 records into 'sbtest4'
Creating secondary indexes on 'sbtest4'...
Creating table 'sbtest5'...
Inserting 100000 records into 'sbtest5'
Creating secondary indexes on 'sbtest5'...
Creating table 'sbtest6'...
Inserting 100000 records into 'sbtest6'
Creating secondary indexes on 'sbtest6'...
Creating table 'sbtest7'...
Inserting 100000 records into 'sbtest7'
Creating secondary indexes on 'sbtest7'...
Creating table 'sbtest8'...
Inserting 100000 records into 'sbtest8'
Creating secondary indexes on 'sbtest8'...
Creating table 'sbtest9'...
Inserting 100000 records into 'sbtest9'
Creating secondary indexes on 'sbtest9'...
Creating table 'sbtest10'...
Inserting 100000 records into 'sbtest10'
Creating secondary indexes on 'sbtest10'...

(2)执行测试 可以将执行结果保存在文件中便于后续分析。

[root@dc2-user]# sysbench ./sysbench-1.0/tests/include/oltp_legacy/oltp.lua --mysql-host=10.254.170.17 --mysql-port=3306 --mysql-user=root --mysql-password=123456 --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 run >> /home/dc2-user/mysysbench.log

(3)清理数据

[root@dc2-user]# sysbench ./sysbench-1.0/tests/include/oltp_legacy/oltp.lua --mysql-host=10.254.170.17 --mysql-port=3306 --mysql-user=root --mysql-password=123456  cleanup

sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Dropping table 'sbtest1'...

##解读测试结果## 打开所保存的测试结果。

[root@dc2-user]# cat mysysbench.log 
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:
Number of threads: 10
Report intermediate results every 10 second(s)
Initializing random number generator from current time


Initializing worker threads...

Threads started!

[ 10s ] thds: 10 tps: 358.81 qps: 7186.31 (r/w/o: 5032.37/1435.32/718.61) lat (ms,95%): 39.65 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 10 tps: 342.69 qps: 6850.20 (r/w/o: 4794.16/1370.66/685.38) lat (ms,95%): 44.98 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 10 tps: 364.58 qps: 7296.91 (r/w/o: 5108.46/1459.40/729.05) lat (ms,95%): 38.25 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 10 tps: 371.62 qps: 7428.24 (r/w/o: 5199.11/1485.79/743.34) lat (ms,95%): 38.94 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 10 tps: 355.44 qps: 7112.96 (r/w/o: 4980.30/1421.77/710.89) lat (ms,95%): 43.39 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 10 tps: 377.68 qps: 7551.83 (r/w/o: 5285.47/1511.01/755.35) lat (ms,95%): 36.89 err/s: 0.00 reconn/s: 0.00
[ 70s ] thds: 10 tps: 378.59 qps: 7572.99 (r/w/o: 5301.26/1514.56/757.18) lat (ms,95%): 38.25 err/s: 0.00 reconn/s: 0.00
[ 80s ] thds: 10 tps: 365.19 qps: 7303.79 (r/w/o: 5113.05/1460.46/730.28) lat (ms,95%): 41.10 err/s: 0.00 reconn/s: 0.00
[ 90s ] thds: 10 tps: 354.24 qps: 7084.59 (r/w/o: 4959.65/1416.36/708.58) lat (ms,95%): 40.37 err/s: 0.00 reconn/s: 0.00
[ 100s ] thds: 10 tps: 372.75 qps: 7453.38 (r/w/o: 5216.16/1491.82/745.41) lat (ms,95%): 38.94 err/s: 0.00 reconn/s: 0.00
[ 110s ] thds: 10 tps: 349.95 qps: 7002.81 (r/w/o: 4902.60/1400.20/700.00) lat (ms,95%): 43.39 err/s: 0.00 reconn/s: 0.00
[ 120s ] thds: 10 tps: 371.82 qps: 7432.30 (r/w/o: 5202.68/1486.08/743.54) lat (ms,95%): 37.56 err/s: 0.00 reconn/s: 0.00
SQL statistics:
    queries performed:
        read:                            611030
        write:                           174580
        other:                           87290
        total:                           872900
    transactions:                        43645  (363.59 per sec.)
    queries:                             872900 (7271.87 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          120.0362s
    total number of events:              43645

Latency (ms):
         min:                                   18.29
         avg:                                   27.49
         max:                                  677.90
         95th percentile:                       40.37
         sum:                              1199972.75

Threads fairness:
    events (avg/stddev):           4364.5000/72.30
    execution time (avg/stddev):   119.9973/0.01

这里一般我们关注这两个指标。

queries:                             872900 (7271.87 per sec.)

95th percentile:                       40.37

我们可以看到QPS为7271.87,95%请求的最大延迟为40.37毫秒,对于当前配置的mysql来说,测试结果比较理想。

关于怎么使用Sysbench对滴滴云MySQL进行基准测试就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。