,," /> " />

目 录CONTENT

文章目录

Sysbench 负载测试

Administrator
2024-02-24 / 0 评论 / 0 点赞 / 12 阅读 / 22389 字

[TOC]

sysbench是一个基于LuaJIT脚本的多线程基准测试工具。2004年由Peter Zaitsev(Percona公司创始人)开发,在其0.5版本中可以使用Lua脚本实现OLTP测试。2016年重构了sysbench代码,并在2017年2月针对新的硬件环境发布了1.0版本,优化了测试性能(是0.5版本的6倍,可以压测60万TPS)和可扩展性(无Mutex、无共享计数器、多线程扩展性更强)。

sysbench不仅可用于数据库基准测试,也可用于服务器的其他工作负载基准测试。本文主要以1.0版本为例介绍sysbench。在新的Release版本下,sysbench新增与优化了如下一些特性。

可以收集有关速率和延迟时间的统计数据,包括延迟百分比和直方图。 低开销,可以执行数以千计的并发线程,能够每秒产生和跟踪数亿个事件。 通过Lua脚本轻松实现了预定义的钩子,以创建新的测试基准。 可以用作通用的Lua脚本解释器,只需在Lua脚本中将“#!/usr/bin/lua”替换为“#!/usr/bin/sysbench”即可。

img

0、预处理

 shell> sync # 将脏数据刷新到磁盘
 shell> echo 3 >/proc/sys/vm/drop_caches # 清除 cache
 shell> swapoff -a && swapon -a  # 如果使用 swap 则释放操作

1 安装sysbench

1.1 yum安装

执行如下命令,设置yum repo仓库/etc/yum.repos.d/akopytov_sysbench.repo,并直接使用yum安装。

RHEL/CentOS

[root@localhost~]# curl -s [https://packagecloud.io/insta...](https://link.segmentfault.com/?enc=aFxFz4QnC0dviffVdmxp5w%3D%3D.h7VQ7d9hmCQR2X5%2FJNSYngEY%2F%2FepxW%2BUguZhzNsVaRTEwUYulKtM6x%2FB%2BzzJXTKepzVIoE%2Fi7Bmg6YxD2lnilw%3D%3D) sysbench/script.rpm.sh | sudo bash

[root@localhost~]# sudo yum -y install sysbench

1.2 RPM包安装

手动下载RPM包来安装(仅限RHEL/CentOS),但是在安装sysbench前需要先安装依赖包,然后再安装该RPM包。

[root@localhost~]# yum install mysql-libs postgresql-libs -y

[root@localhost~]# rpm -Uvh sysbench-1.0.7-13.el6.x86_64.rpm --nodeps

由于sysbench编译时依赖libmysqlclient动态链接库,所以要选择对应版本的sysbench,或者使用软链接:

[root@localhost~]# ln -s /usr/lib64/mysql/libmysqlclient.so.18 /usr/lib64/ libmysqlclient_r.\ so.16

1.3 编译安装

安装依赖的编译环境:

RHEL/CentOS

[root@localhost~]# yum -y install make automake libtool pkgconfig libaio-devel vim-\
common git

For MySQL support, replace with mysql-devel on RHEL/CentOS 5

[root@localhost~]# yum -y install mariadb-devel

For PostgreSQL support

[root@localhost~]# yum -y install postgresql-devel

最新的sysbench程序包地址为[https://github.com/akopytov/s...](https://link.segmentfault.com/?enc=TMdhpWo2VrfBSRW7FiY0Sg%3D%3D.vncwDncnD%2B5xkDM08N5IwM%2Bikvk18KYz12xYy47rdAt6vhWAbIfK3oCNwVhlHniU),直接下载并解压缩程序包:

[root@localhost~]# wget

 [https://github.com/akopytov/s...](https://link.segmentfault.com/?enc=ax53e7h2ibAG6cdd1E04Aw%3D%3D.HkKhcc%2B5x7B2voNwCXF7MRYYsSVej75bu6kDAsV2r8AKCwTjD2Ve%2BwHX2dDN5de1Z7hsLbBgrdahFd%2FfzrbUSg%3D%3D)

[root@localhost~]# tar zxf sysbench-1.0.13.tar.gz

编译安装:

[root@localhost~]# cd sysbbench-1.0.13

[root@localhost~]# ./autogen.sh

Add --with-pgsql to build with PostgreSQL support

[root@localhost~]# ./configure

[root@localhost~]# make

[root@localhost~]# make install

1.4 验证安装是否成功

查看版本信息,如果可以正常查看到版本信息而不报错,则说明sysbench安装成功。

[root@localhost~]# sysbench --version  

2 测试案例

本节通过几个测试案例简单介绍如何使用sysbench对MySQL数据库进行压力测试。

sysbench除能压测数据库性能之外,还能对其他一些测试对象进行性能测试,包括CPU、内存、线程等的压测,限于篇幅,这里不详细介绍,读者可以参考链接:Sysbench - Gentoo Wiki来进一步了解。

在测试前,请先创建好MySQL账户qbench@127.0.0.1(密码为qbench),确保该账户可以正常连接到数据库,并且拥有sbtest库的所有权限。下面就利用4个并发线程,对一个MySQL实例上的32个500万行数据的表(sbtest1, sbtest2, … ,sbtest32)进行180s的压力测试,以查看MySQL数据库在压力下的表现。

2.1 造数

可以直接使用Lua脚本前缀作为testname,使用prepare命令造数。


[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1\ --mysql-host =127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench\ --mysql-db= sbtest --tables=32 --table-size=5000000 oltp_read_write --db-ps-mode=disable\ prepare

2.2 数据库读写测试

1.oltp_read_write

该测试案例对应sysbench 0.5版本的oltp.lua脚本,用于测试数据库的TPS性能。

[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1 --mysql-host =127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench –mysql -db =sbtest --tables=32 --table-size=5000000 oltp_read_write --db-ps-mode=disable run

2.oltp_read_only

该测试案例对应sysbench 0.5版本的select.lua脚本,用于测试数据库的只读性能。

[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench --mysql-db=sbtest --tables=32 --table-size=5000000 oltp_read_only --db-ps-mode=disable run

3.oltp_delete

该测试案例对应sysbench 0.5版本的delete.lua脚本,用于测试数据库的删除性能。

[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench --mysql-db=sbtest --tables=32 --table-size=5000000 oltp_delete --db-ps-mode=disable run

4.oltp_update_index

该测试案例对应sysbench 0.5版本的update_index.lua脚本,用于测试数据库的更新索引性能。

[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench --mysql-db=sbtest --tables=32 --table-size=5000000 oltp_update_index --db-ps-mode=disable run

5.oltp_update_non_index

该测试案例对应sysbench 0.5版本的update_non_index.lua脚本,用于测试数据库的更新非索引字段性能。

[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench --mysql-db=sbtest --tables=32 --table-size=5000000 oltp_update_non_index --db-ps-mode=disable run

6.oltp_insert

该测试案例对应sysbench 0.5版本的insert.lua脚本,用于测试数据库的插入性能。

[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench --mysql-db=sbtest --tables=32 --table-size=5000000 oltp_insert --db-ps-mode=disable run

7.oltp_write_only

该测试案例是sysbench 1.0.x版本新增的,与原来的oltp.lua相比,少了select部分。

[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1 –mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench –mysql-db=sbtest --tables=32 --table-size=5000000 oltp_write_only --db-ps-mode=disable run

2.3 清理

使用cleanup命令清理prepare和run产生的数据,实际上是删除对应的表。

[root@localhost~]# sysbench --db-driver=mysql --time=180 --threads=4 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qbench --mysql-db=sbtest --tables=32 --table-size=5000000 oltp_read_write --db-ps-mode=disable cleanup

3 sysbench 参数详解

3.1 sysbench命令语法

sysbench命令语法如下:


sysbench [options]... [testname] [command]

options(参数选项):用于指定sysbench的并发度、压测时长等参数。
testname(测试名称):用于指定sysbench的基准测试名称,可选项包括oltp_read_ write、oltp_read_only、oltp_write_only、oltp_insert、oltp_delete、oltp_update_index、oltp_update_non_index等
command(测试命令):用于指定sysbench执行什么测试命令,可选项包括prepare、run、cleanup等。

3.2 options

下面逐一介绍相关选项。

1.常规选项

--threads=N:指定线程数,默认值为1,相当于sysbendh 0.5及之前版本中的--num-threads=N选项。
--events=N:指定总的请求数,默认值为0,表示不限制请求数,相当于sysbench 0.5及之前版本中的--max-requests选项。
--time=N:指定压测时长,默认值为10s,相当于sysbench 0.5及之前版本中的--max-time=N选项。
--forced-shutdown=STRING:有效值为off、N、N%(默认值为off)。off表示不启用强制关机功能;N表示在--time选项指定的时间到期后,再过N秒强制关机;N%表示在--time选项指定的时间到期后,再过--time*N%时间强制关机。
--thread-stack-size=SIZE:指定每个线程的堆栈大小,默认值为64KB。
--rate=N:限定事务速率(tps),默认值为0,表示不限制,相当于sysbench 0.5及之前版本中的--tx-rate=N选项。
--report-interval=N:指定中间统计结果报告的间隔时间,默认值为0,表示关闭中间统计结果报告输出。
--report-checkpoints=[LIST,...]:用逗号分隔的一组列表值,这些值在执行sysbench压测时被依次读取,表示执行多少秒就打印一次统计报告(例如--report- checkpoints=10,20,30,表示当执行10s、20s、30s时分别打印一次统计报告。注意,该数值是指从执行sysbench开始到现在的时间),默认值为空,表示在--time选项指定的时间到期后才打印统计报告。
--debug[=on|off]:是否打印调试信息,默认值为off。
--help[=on|off]:是否打印帮助信息,默认值为off。
--version[=on|off]:是否打印版本信息,默认值为off。

2.伪随机数创建选项

--rand-type=STRING:随机数分布类型,可选项包括uniform、gaussian、special、pareto,默认值为special。
--rand-spec-iter=N:随机数生成的迭代次数,默认值为12次。
--rand-spec-pct=N:对特定随机数分布来说被视为“特殊”值的百分比,默认值为1。
--rand-spec-res=N:对特定随机数分布来说“特殊”值的百分比,默认值为75。
--rand-seed=N:随机数发生器的种子。当该选项设置为0时,表示使用当前时间作为RNG种子。
--rand-pareto-h=N:用于指定pareto随机分布的h参数,默认值为0.2。

3.日志选项

--verbosity=N:日志打印的详细程度,5表示打印debug级别以上的日志,0表示只打印critical级别以上的日志。默认值为3。
--percentile=N:在延迟时间统计中选择哪个百分位数,可选范围为(1~100),默认值为95。如果设置为0,则表示禁用延迟时间统计功能。
--histogram[=on|off]:是否打印延迟时间直方图报告,默认值为off。

4.常规数据库选项

--db-driver=STRING:指定数据库驱动程序(即指定数据库类型),当前版本支持MySQL和PostgreSQL。
--db-ps-mode=STRING:prepare命令使用模式,有效值为auto和disable,默认值为auto,在高并发压力下建议使用disable。
--db-debug[=on|off]:是否打印数据库的调试信息,默认值为off。

5.MySQL选项

--mysql-host=MySQL服务器主机,默认值为localhost。
--mysql-port=MySQL服务器端口号,默认值为3306。
--mysql-socket= MySQL服务器Socket文件目录。
--mysql-user=连接MySQL服务器的用户名,默认值为sbtest。
--mysql-password=连接MySQL服务器的密码。
--mysql-db=连接MySQL服务器的数据库名,默认值为sbtest。
--mysql-ssl[=on|off]:连接MySQL服务器是否使用SSL,默认值为off。
--mysql-ssl-cipher=连接MySQL服务器使用SSL时的Cipher。
--mysql-compression[=on|off]:连接MySQL服务器是否使用压缩,默认值为off。
--mysql-debug[=on|off]:连接MySQL服务器是否跟踪所有的客户端库调用,默认值为off。
--mysql-ignore-errors=是否忽略MySQL返回的错误,默认值为[1213,1020,1205]。
--mysql-dry-run[=on|off]:是否空跑,只是调用MySQL客户端API,但是不真正执行。

6.pgsql选项

--pgsql-host= PostgreSQL服务器主机,默认值为localhost。
--pgsql-port= PostgreSQL服务器端口,默认值为5432。
--pgsql-user=连接MySQL服务器的用户名,默认值为sbtest。
--pgsql-password=连接MySQL服务器的密码。
--pgsql-db=连接MySQL服务器的数据库名,默认值为sbtest。

7.其他选项 通过使用如下命令来查看额外的关于测试名称(事务模型)命令选项,只需要任意指定一个测试名称即可。

指定oltp_read_write测试名称来查看额外的帮助选项

[root@localhost ]# sysbench oltp_read_write help  

......

oltp_read_write options:

 --distinct_ranges=N Number of SELECT DISTINCT queries per transaction [1]

 --sum_ranges=N Number of SELECT SUM() queries per transaction [1]

 --skip_trx[=on|off] Don't start explicit transactions and execute all queries in the AUTOCOMMIT mode [off]

……

各选项解释如下。

--distinct_ranges=N:指定在每个事务中SELECT DISTINCT查询的执行次数,默认值为1。
-sum_ranges=N:指定在每个事务中SELECT SUM()查询的执行次数,默认值为1。
--skip_trx[=on|off]:指定在AUTOCOMMIT(自动提交)模式下是否需要跳过启动显式事务(使用START语句显式启动一个事务),默认值为off。
--secondary[=on|off]:指定是否需要使用一个二级索引来代替主键索引,默认值为off。
--create_secondary[=on|off]:指定除主键之外,是否还需要创建一个二级索引,默认值为on。
--index_updates=N:指定在每个事务中使用索引执行UPDATE语句的次数,默认值为1。
--range_size=N:指定在每个事务中范围SELECT查询的条件值,默认值为100。
--auto_inc[=on|off]:指定是否需要使用自增列的自增值作为主键值,如果不使用自增值,则使用sysbench自动生成的ID值作为主键值,默认值为on。
--delete_inserts=N:指定在每个事务中DELETE/INSERT组合语句的数量,默认值为1。
--tables=N:指定并行压测的表数量。
--mysql_storage_engine=STRING:指定表的存储引擎,默认值为InnoDB。
--non_index_updates=N:指定在每个事务中不使用索引执行UPDATE语句的次数,默认值为1。
--table_size=N:指定每个表的数据总量,默认值为10 000。
--pgsql_variant=STRING:当用PostgreSQL驱动程序运行时使用此PostgreSQL变体。目前唯一支持的变体是“redshift”。启用后,将自动禁用create_secondary,并将--delete_inserts选项设置为0。
--simple_ranges=N:指定在每个事务中简单范围SELECT查询(这里指的是BETWEEN范围查询)的次数,默认值为1。
--order_ranges=N:指定在每个事务中SELECT ORDER BY查询的次数,默认值为1。
--range_selects[=on|off]:指定是否需要打开或关闭所有的范围SELECT查询,默认值为on。
--point_selects=N:指定在每个事务中单行SELECT查询的次数,默认值为10。

每一种测试名称对应的Lua脚本中都定义了需要使用的DML测试语句类型,每一种DML语句类型都可以通过选项单独指定在每一个事务中需要执行多少次。例如,在oltp_read_write测试名称中,一共有9种DML语句类型,按照默认的每一种语句的执行次数计算,在每一个事务中一共有18条语句,每一种DML语句类型的默认执行次数如下:

 简单等值SELECT语句:默认为10次。
- 范围SELECT(BETWEEN)语句:默认为1次。
- SELECT SUM()语句:默认为1次。
- SELECT ORDER BY:默认为1次。
- SELECT DISTINCT语句:默认为1次。
- DELETE和INSERT组合语句:默认为1次。
- 使用索引的UPDATE语句:默认为1次。
- 不使用索引的UPDATE语句:默认为1次。
在执行oltp_read_write测试时,从MySQL的general_log中抓取的每个事务的语句数量也证实了,在默认的配置下一个事务中的语句数量为18条,如下图所示。
![image.png](Untitled.assets/bVc0ATn.png)

3.3 testname

testname用于指定sysbench的基准测试名称。基准测试包括:

oltp _*.lua,数据库基准测试Lua脚本集合。这是DBA日常经常需要用到的测试脚本。
fileio,文件系统级基准测试。
cpu,简单的CPU基准测试。
memory,内存访问基准测试。
threads,基于线程的调度器基准测试。
mutex,POSIX互斥基准测试。

提示:在实际执行时,对于Lua新格式脚本,可以只写脚本名称(不写.lua后缀),如oltp_read_only,不再需要像sysbench 0.5及之前版本那样使用--test选项来指定。

1.sysbench Lua脚本介绍 Sysbench 1.0.x版本中的Lua脚本代码比0.5.x版本工整得多,并且对结构进行了重新设计,大部分SQL语句都被整合到了oltp_common.lua脚本中集中定义,其他Lua脚本只需要加载这个脚本进行调用即可。另外,还对原来的delete.lua、select.lua、update*.lua、insert.lua脚本中的SQL语句进行了改进,将其嵌套到begin和commit语句中。

通过RPM包安装的sysbench 1.0.x版本中的Lua脚本有两个目录,如下所示。

[root@localhost~]# ls -lh /usr/share/sysbench/ /usr/share/sysbench/tests/include/\ oltp_legacy

/usr/share/sysbench/:  #对于sysbench 1.0.x版本,建议使用这个目录下的最新的Lua脚本。不过该脚本使用prepare命令执行语句,需要创建大量的prepare命令对象,调整参数的值

total 64K

-rwxr-xr-x 1 root root 1.5K May 15 22:14 bulk_insert.lua

-rw-r--r-- 1 root root  14K May 15 22:14 oltp_common.lua

-rwxr-xr-x 1 root root 1.1K May 15 22:14 oltp_delete.lua

-rwxr-xr-x 1 root root 2.0K May 15 22:14 oltp_insert.lua

-rwxr-xr-x 1 root root 1.3K May 15 22:14 oltp_point_select.lua

-rwxr-xr-x 1 root root 1.7K May 15 22:14 oltp_read_only.lua

-rwxr-xr-x 1 root root 1.8K May 15 22:14 oltp_read_write.lua

-rwxr-xr-x 1 root root 1.1K May 15 22:14 oltp_update_index.lua

-rwxr-xr-x 1 root root 1.2K May 15 22:14 oltp_update_non_index.lua

-rwxr-xr-x 1 root root 1.5K May 15 22:14 oltp_write_only.lua

-rwxr-xr-x 1 root root 1.9K May 15 22:14 select_random_points.lua

-rwxr-xr-x 1 root root 2.1K May 15 22:14 select_random_ranges.lua

drwxr-xr-x 4 root root 4.0K Jun 15 15:53 tests



/usr/share/sysbench/tests/include/oltp_legacy: # 对于sysbench 1.0.x版本,在这个目录下保留了一些兼容之前版本写法的Lua脚本

total 52K

-rw-r--r-- 1 root root 1.2K May 15 22:14 bulk_insert.lua

-rw-r--r-- 1 root root 4.6K May 15 22:14 common.lua

-rw-r--r-- 1 root root  366 May 15 22:14 delete.lua

-rw-r--r-- 1 root root 1.2K May 15 22:14 insert.lua

-rw-r--r-- 1 root root 3.0K May 15 22:14 oltp.lua

-rw-r--r-- 1 root root  368 May 15 22:14 oltp_simple.lua

-rw-r--r-- 1 root root  527 May 15 22:14 parallel_prepare.lua

-rw-r--r-- 1 root root  369 May 15 22:14 select.lua

-rw-r--r-- 1 root root 1.5K May 15 22:14 select_random_points.lua

-rw-r--r-- 1 root root 1.6K May 15 22:14 select_random_ranges.lua

-rw-r--r-- 1 root root  369 May 15 22:14 update_index.lua

-rw-r--r-- 1 root root  578 May 15 22:14 update_non_index.lua

关于Lua语法请参考:[http://www.runoob.com/lua/lua...](https://link.segmentfault.com/?enc=ldubeTIqdzdXpaXUzAkUfQ%3D%3D.H8L4im5NSUwCr3CX3xkwzzo3eCKCnY1w3vYNcfwYXQ7e%2F2q0SABktvPsTS4Pt6kY)。

2.自定义Lua脚本

为了实现自定义测试,读者也可以自定义Lua脚本,使用sysbench进行测试。

下面是一个简单的示例。

function prepare()

   db_query("CREATE TABLE t (a INT)")

   db_query("INSERT INTO t VALUES (1)")

end



function event()

   db_query("UPDATE t SET a = a + " .. sb_rand(1, 1000))

end



function cleanup()

   db_query("DROP TABLE t")

end

使用sysbench测试如下:

calls prepare()

[root@localhost~]# sysbench --test=test.lua prepare

calls event() in a loop

[root@localhost~]# sysbench --test=test.lua --num-threads=16 --report-interval=1 run

[ 1s] threads: 16, tps: 0.00, reads: 0.00, writes: 13788.65, response time: 1.43ms (95%)

[ 2s] threads: 16, tps: 0.00, reads: 0.00, writes: 14067.56, response time: 1.40ms (95%)

...

$ sysbench --test=test.lua cleanup # calls cleanup()

3.4 command

command将由sysbench传递给内置的testname或testname指定的Lua脚本。该命令指定testname需要执行的操作。

以下是典型的测试命令及其描述。

prepare:执行准备工作。例如,在磁盘上创建必要的测试文件以进行fileio测试,或者在测试数据库上新建100万行数据以执行数据库基准测试。 run:使用testname参数指定的压测脚本执行对应的测试。 cleanup:在测试结束后删除临时数据或文件。 help:显示使用testname参数指定的压测脚本的相关帮助信息,包括该压测脚本参数的完整列表。例如sysbench oltp_write_only help,可以查看oltp_write_only压测脚本支持的所有可选参数。

4 数据库测试输出信息详解

下面详细介绍使用sysbench测试MySQL数据库的输出结果。

[root@localhost~]# sysbench --db-driver=mysql --time=10 --threads=4 --report-interval=1\ --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=qbench --mysql-password=qb

[14/480]

ysql-db=sbtest --tables=32 --table-size=50000 oltp_read_write --db-ps-mode=disable run

sysbench 1.0.7 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:

Number of threads: 4

Report intermediate results every 1 second(s)

Initializing random number generator from current time

Initializing worker threads...

Threads started!



[ 1s ] thds: 4 tps: 374.23 qps: 7533.43 (r/w/o: 5280.08/977.98/1275.36) lat (ms,95%): 17.95 err/s: 0.00 reconn/s: 0.00

[ 2s ] thds: 4 tps: 329.07 qps: 6604.49 (r/w/o: 4622.04/880.20/1102.25) lat (ms,95%): 21.11 err/s: 0.00 reconn/s: 0.00

[ 3s ] thds: 4 tps: 362.00 qps: 7225.05 (r/w/o: 5054.04/943.01/1228.01) lat (ms,95%): 18.61 err/s: 0.00 reconn/s: 0.00

[ 4s ] thds: 4 tps: 392.00 qps: 7847.05 (r/w/o: 5494.04/1069.01/1284.01) lat (ms,95%): 17.63 err/s: 0.00 reconn/s: 0.00

[ 5s ] thds: 4 tps: 331.01 qps: 6602.18 (r/w/o: 4625.12/894.02/1083.03) lat (ms,95%): 20.37 err/s: 0.00 reconn/s: 0.00

[ 6s ] thds: 4 tps: 334.99 qps: 6712.77 (r/w/o: 4698.84/929.97/1083.96) lat (ms,95%): 19.65 err/s: 0.00 reconn/s: 0.00

[ 7s ] thds: 4 tps: 356.97 qps: 7149.40 (r/w/o: 5002.58/985.92/1160.90) lat (ms,95%): 19.29 err/s: 0.00 reconn/s: 0.00

[ 8s ] thds: 4 tps: 333.01 qps: 6657.20 (r/w/o: 4663.14/926.03/1068.03) lat (ms,95%): 20.37 err/s: 0.00 reconn/s: 0.00

[ 9s ] thds: 4 tps: 347.03 qps: 6950.59 (r/w/o: 4860.41/972.08/1118.09) lat (ms,95%): 20.37 err/s: 0.00 reconn/s: 0.00

[ 10s ] thds: 4 tps: 342.97 qps: 6821.44 (r/w/o: 4773.61/932.92/1114.91) lat (ms,95%): 19.29 err/s: 0.00 reconn/s: 0.00

SQL statistics:

   queries performed:

​     read: 49084

​     write: 9513

​     other: 11523

​     total: 70120

   transactions: 3506 (350.33 per sec.)

   queries: 70120 (7006.63 per sec.)

   ignored errors: 0 (0.00 per sec.)

   reconnects: 0 (0.00 per sec.)



General statistics:

   total time: 10.0062s

   total number of events: 3506



Latency (ms):

​     min: 4.56

​     avg: 11.41

​     max: 39.24

​     95th percentile: 19.65

​     sum: 39997.58



Threads fairness:

   events (avg/stddev): 876.5000/5.22

   execution time (avg/stddev): 9.9994/0.00

4.1 输出结果概述

Sysbench测试输出结果主要分为三部分: 版本及关键测试参数输出。 中间统计结果输出。 整体统计结果输出。

4.2 版本及关键测试参数输出

在sysbench测试正常开始以后,首先输出的是sysbench的版本、压测线程个数、每隔几秒输出一次中间结果、随机数初始化等相关信息。

4.3 中间统计结果输出

在指定了--report-interval参数以后,每隔report-interval时间输出一次中间统计结果,如下所示。

==[ 6s ] thds: 4 tps: 334.99 qps: 6712.77 (r/w/o: 4698.84/929.97/1083.96) lat (ms,95%): 19.65 err/s: 0.00 reconn/s: 0.00==

[ 6s ]:表示当前已经压测6s。
thds: 4:表示4个线程并发压测。
tps: 334.99:表示在report-interval时间间隔内的每秒事务数。
qps: 6712.77:表示在report-interval时间间隔内的每秒查询数。
(r/w/o: 4698.84/929.97/1083.96):表示在report-interval时间间隔内的每秒读/写/其他请求数,用于补充说明qps。

lat (ms,95%):19.65:表示在report-interval时间间隔内的请求95%的延迟时间在19.65ms以下。
err/s: 0.00:表示在report-interval时间间隔内的每秒失败请求数。
reconn/s: 0.00:表示在report-interval时间间隔内的每秒重连接数。

4.4 整体统计结果输出

在sysbench全部测试完成以后,将输出整体压测的统计结果。主要分为四部分: (1)SQL统计结果 该项输出结果包括sysbench发起的读/写/其他/总计SQL查询数量、总计事务数及每秒事务数、总计请求数及每秒请求数、总计错误数及每秒错误数、总计重连接数及每秒重连接数。

SQL statistics:

   queries performed:

​     read: 49084

​     write: 9513

​     other: 11523

​     total: 70120

   transactions: 3506 (350.33 per sec.)

   queries: 70120 (7006.63 per sec.)

   ignored errors: 0 (0.00 per sec.)

   reconnects: 0 (0.00 per sec.)

(2)通用统计值

该项输出结果包括总计执行的时间、所有的事件数量(这里对应的是发起的MySQL事务数)。

General statistics:

   total time: 10.0062s

   total number of events: 3506

(3)延迟时间统计结果

该项输出结果包括延迟时间最低值、平均值、最高值、第95%位值、总计值。

Latency (ms):

​     min: 4.56

​     avg: 11.41

​     max: 39.24

​     95th percentile: 19.65

​     sum: 39997.58

(4)压测线程统计结果

该项输出结果包括每个压测线程的平均事件数及标准差、每个事务的平均执行时间及标准差。

Threads fairness:

   events (avg/stddev): 876.5000/5.22

   execution time (avg/stddev): 9.9994/0.00

5、详解说明

 ## 结果统计信息
 SQL statistics:
    queries performed:
        read:                    6308960     # ---> 读总数
        write:                   1138382     # ---> 写总数
        other:                   1565372     # ---> 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
        total:                   9012714     # ---> 全部总数
    transactions:                450597 (1251.33 per sec.)   # ---> 总事务数(每秒事务平均速率)
    queries:                     9012714 (25028.66 per sec.) # ---> 查询总数 (平均每秒能执行多少次查询)
    ignored errors:              43     (0.12 per sec.)      # ---> 忽略错误总数(每秒忽略错误次数)忽略错误总数(每秒忽略错误次数)
    reconnects:                  0     (0.00 per sec.)      # ---> 重连总数(每秒重连次数)
 
 Throughput:  # 通用统计值
    events/s (eps):                   1251.3254   # --> 每秒TPS
    time elapsed:                     360.0958s   # --> 总耗时
    total number of events:           450597      # --> 总请求数量(读、写、其它)
 
 Latency (ms): # 延迟时间统计
        min:                            12.37       # --> 最小耗时
        avg:                            79.89       # --> 平均耗时
        max:                          1093.24       # --> 最长耗时
        95th percentile:               130.13       # --> 超过95%平均耗时(毫秒)
        sum:                      35999872.07  
 
 Threads fairness:  # ---> 并发统计
    events (avg/stddev):           4505.9700/69.21      # ---> 总处理事件数/标准偏差
    execution time (avg/stddev):   359.9987/0.03        # ---> 总执行时间/标准偏差

QPS、TPS、

2. 性能指标
通过我们看各大厂商提供的指标,我们不难发现,主要是 4 个指标:

TPS :Transactions Per Second ,即数据库每秒执行的事务数,以 commit 成功次数为准。
QPS :Queries Per Second ,即数据库每秒执行的 SQL 数(含 insert、select、update、delete 等)。
RT :Response Time ,响应时间。包括平均响应时间、最小响应时间、最大响应时间、每个响应时间的查询占比。比较需要重点关注的是,前 95-99% 的最大响应时间。因为它决定了大多数情况下的短板。
Concurrency Threads :并发量,每秒可处理的查询请求的数量。
如果对基准测试不是很理解的胖友,可以看下 《详解 MySQL 基准测试和 sysbench 工具》 的第一部分基准测试简介。

总结来说,实际就是 2 个维度:

吞吐量
延迟

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区