因sysbench版本更新问题,某些命令选项发生改变,查询help进行酌情更改。

https://yq.aliyun.com/articles/66651?spm=5176.100239.blogcont66870.15.0ouYNm

http://imysql.cn/2014/10/17/sysbench-full-user-manual.shtml

摘要:为什么要测试,测什么东西? 测试的种类非常多,测试的目的也非常多,我这里主要的目的就两个 测试MySQL的极限IO 对比不同版本MySQL,不同参数, 不同硬件,不同系统对MySQL的性能影响 为什么选择sysbench 因为MySQL官方的测试就是用sysbench哦 尽量选择最新版本

为什么要测试,测什么东西?

测试的种类非常多,测试的目的也非常多,我这里主要的目的就两个

测试MySQL的极限IO

对比不同版本MySQL,不同参数, 不同硬件,不同系统对MySQL的性能影响

为什么选择sysbench因为MySQL官方的测试就是用sysbench哦尽量选择最新版本的sysbench哦,大于0.4版本的sysbench有实时显示功能如何下载sysbench

http://github.com/akopytov/sysbench

文档在哪里

http://github.com/akopytov/sysbench

如何安装

* 基本步骤 cd sysbench-1.0;./autogen.sh;./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib/;make;make install;

* 过程中可能会遇到的故障

sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory

* 解决方案 export LD_LIBRARY_PATH=/usr/local/mysql/lib/;

* 测试是否安装成功 shell> sysbench --version sysbench 1.0 介绍sysbench的核心用法

它可以用来测试很多东西,测试io,cpu,mem,mysql,oracle,pg等等。这里主要介绍我关心的两个,IO & MySQL以下前半部分是0.4版本的用法,0.4以上的版本用法不一样,会注明。
一、通用语法

sysbench [common-options] --test=name [test-options] command command

* prepare 准备阶段,也就是装载数据。 filo test 中: 就是创建指定大小的文件 oltp test 中: 就是创建指定大小的表

* run 实际测试阶段

* cleanup 收尾阶段,清除之前测试的数据。 common-options

只介绍常用的选项

选项描述默认值--num-threads多少个线程1--max-requests多少个请求,0意味着无限制1000--max-time测试多长时间,0意味着无限制0--test测试什么模块必须要求--report-interval阶段性的汇报测试统计信息,0.4以上版本新增--test=fileio 模块的选项

提前注明:--file-test-mode

* seqwrsequential write

* seqrewrsequential rewrite

* seqrd

sequential read

* rndrd random read

* rndwr random write

* rndrwcombined random read/write test option for fileio选项描述默认值--file-num创建文件的数量128--file-block-sizeIO操作的大小16k--file-total-size所有文件的总大小2G--file-test-modeseqwr,seqrewr, seqrd, rndrd, rndwr, rndwr(上面已经介绍)必须--file-io-modei/O 模式,sync, async, fastmmap, slowmmapsync--file-extra-flags以额外的标记(O_SYNC,O_DSYNC,O_DIRECT)打开---file-fsync-freq多少请求后使用fsync100--file-fsync-all每次写IO都必须fsyncno--file-fsync-mode用什么样的模式来同步文件fsync, fdatasync (see above)fsync--file-rw-ratio随机读写请求的比例1.5

举例:

$ sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw prepare$ sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw run

$ sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw cleanupOLTP-MySQL

此模式用于测试真实数据库性能。在prepare阶段创建表,sbtest默认

CREATE TABLE `sbtest` ( `id` int(10) unsigned NOT NULL auto_increment, `k` int(10) unsigned NOT NULL default '0', `c` char(120) NOT NULL default '', `pad` char(60) NOT NULL default '',PRIMARY KEY (`id`), KEY `k` (`k`));

在run阶段

simple模式

SELECT c FROM sbtest WHERE id=N Point queries

SELECT c FROM sbtest WHERE id=N Range queries:

SELECT c FROM sbtest WHERE id BETWEEN N AND M Range SUM() queries

SELECT SUM(K) FROM sbtest WHERE id BETWEEN N and M Range ORDER BY queries

SELECT c FROM sbtest WHERE id between N and M ORDER BY c Range DISTINCT queries

SELECT DISTINCT c FROM sbtest WHERE id BETWEEN N and M ORDER BY c UPDATEs on index column

UPDATE sbtest SET k=k+1 WHERE id=N UPDATEs on non-index column:

UPDATE sbtest SET c=N WHERE id=M DELETE queries

DELETE FROM sbtest WHERE id=N INSERT queries

INSERT INTO sbtest VALUES (...) oltp test 模式通用参数选项描述默认值--oltp-table-name表的名字sbtest--oltp-table-size表的行数10000--oltp-tables-count表的个数1--oltp-dist-type热点数据分布{uniform(均匀分布),Gaussian(高斯分布),special(空间分布)}。默认是specialspecial--oltp-dist-pctspecial:热点数据产生的比例1--oltp-dist-resspecial:热点数据的访问频率75--oltp-test-modesimple,complex(以上介绍)complex--oltp-read-only只有select 请求off--oltp-skip-trx不用事务off--oltp-point-selects一个事务中简单select查询数量10--oltp-simple-ranges一个事务中简单range查询的数量1--oltp-sum-rangessum range的数量1--oltp-order=rangesorder range的数量1mysql test 参数

--mysql-host=[LIST,...] MySQL server host [localhost]

--mysql-port=[LIST,...] MySQL server port [3306]

--mysql-socket=[LIST,...] MySQL socket

--mysql-user=STRING MySQL user [sbtest]

--mysql-password=STRING MySQL password []

--mysql-db=STRING MySQL database name [sbtest]

--mysql-table-engine=STRING storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]

--mysql-engine-trx=STRING whether storage engine used is transactional or not {yes,no,auto} [auto]

--mysql-ssl=[on|off] use SSL connections, if available in the client library [off]

--mysql-ssl-cipher=STRING use specific cipher for SSL connections []

--mysql-compression=[on|off] use compression, if available in the client library [off]

--myisam-max-rows=N max-rows parameter for MyISAM tables [1000000]

--mysql-debug=[on|off] dump all client library calls [off]

--mysql-ignore-errors=[LIST,...]list of errors to ignore, or "all" [1213,1020,1205]

--mysql-dry-run=[on|off] Dry run, pretent that all MySQL client API calls are successful without executing them [off]

以上0.4版本的语法介绍完毕。

接下来是大于0.4版本的新语法,尤其是--test=oltp模块

用--test=xx.lua (完整路径来传递)来代替
[szq@upright91 local]$ locate select.lua
/home/szq/sysbench-1.0.3/src/lua/oltp_point_select.lua
/home/szq/sysbench-1.0.3/tests/include/oltp_legacy/select.lua
/usr/local/share/sysbench/oltp_point_select.lua
/usr/local/share/sysbench/tests/include/oltp_legacy/select.lua
[szq@upright91 local]$ ll /home/szq/sysbench-1.0.3/tests/include/oltp_legacy
总用量 52
-rw-r--r-- 1 szq szq 1195 2月 26 05:12 bulk_insert.lua
-rw-r--r-- 1 szq szq 4696 2月 26 05:12 common.lua
-rw-r--r-- 1 szq szq 366 2月 26 05:12 delete.lua
-rw-r--r-- 1 szq szq 1171 2月 26 05:12 insert.lua
-rw-r--r-- 1 szq szq 3004 2月 26 05:12 oltp.lua
-rw-r--r-- 1 szq szq 368 2月 26 05:12 oltp_simple.lua
-rw-r--r-- 1 szq szq 527 2月 26 05:12 parallel_prepare.lua
-rw-r--r-- 1 szq szq 369 2月 26 05:12 select.lua
-rw-r--r-- 1 szq szq 1448 2月 26 05:12 select_random_points.lua
-rw-r--r-- 1 szq szq 1556 2月 26 05:12 select_random_ranges.lua
-rw-r--r-- 1 szq szq 369 2月 26 05:12 update_index.lua
-rw-r--r-- 1 szq szq 578 2月 26 05:12 update_non_index.lua

FileIO实战

磁盘:S3610 * 6 raid10, 内存128G
测试出相关场景下的极限IOPS

随机读写(3:2 oltp场景)

* sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300 --test=fileio --file-num=200 --file-total-size=200G \

--file-test-mode=rndrw --file-block-size=16384 --file-extra-flags=direct run

随机读写(5:1 oltp场景)

* sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300 --test=fileio --file-num=200 --file-total-size=200G \

--file-test-mode=rndrw --file-block-size=16384 --file-extra-flags=direct --file-rw-ratio=5 run

随机写

* sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300 --test=fileio --file-num=200 --file-total-size=200G \

--file-test-mode=rndwr --file-block-size=16384 --file-extra-flags=direct run

随机读

* sysbench --num-threads=16 --report-interval=3 --max-requests=0 --max-time=300 --test=fileio --file-num=200 --file-total-size=200G \

--file-test-mode=rndrd --file-block-size=16384 --file-extra-flags=direct run

MySQL5.6 vs MySQL5.7 测试

磁盘:S3610 * 6 raid10, 内存128G

Point select

* 产生数据 sysbench --num-threads=128 --report-interval=3 --max-requests=0 --max-time=300 --test=/root/sysbench-1.0/sysbench/tests/db/select.lua \

--mysql-table-engine=innodb --oltp-table-size=50000000 --mysql-user=sysbench --mysql-password=sysbench --oltp-tables-count=2 --mysql-host=xx --mysql-port=3306 prepare

* 执行 sysbench --num-threads=128 --report-interval=3 --max-requests=0 --max-time=300 --test=/root/sysbench-1.0/sysbench/tests/db/select.lua \

--mysql-table-engine=innodb --oltp-table-size=50000000 --mysql-user=sysbench --mysql-password=sysbench --oltp-tables-count=2 --mysql-host=xx --mysql-port=3306 run

Point oltp

* 产生数据 sysbench --num-threads=128 --report-interval=3 --max-requests=0 --max-time=300 --test=/root/sysbench-1.0/sysbench/tests/db/oltp.lua \

--mysql-table-engine=innodb --oltp-table-size=50000000 --mysql-user=sysbench --mysql-password=sysbench --oltp-tables-count=2 --mysql-host=xx --mysql-port=3306 prepare

* 执行 sysbench --num-threads=128 --report-interval=3 --max-requests=0 --max-time=300 --test=/root/sysbench-1.0/sysbench/tests/db/oltp.lua \

--mysql-table-engine=innodb --oltp-table-size=50000000 --mysql-user=sysbench --mysql-password=sysbench --oltp-tables-count=2 --mysql-host=xx --mysql-port=3306 run

结论
在性能方面,虽然官方号称5.7性能比5.6快3倍,但是在实际测试中5.7比5.6却稍微差一点点是否会选择5.7生产环境?当然,因为5.7的新特性太诱人了
参考:

https://www.percona.com/blog/2016/04/07/mysql-5-7-sysbench-oltp-read-results-really-faster/
http://dimitrik.free.fr/blog/archives/2013/09/mysql-performance-reaching-500k-qps-with-mysql-57.html
https://github.com/akopytov/sysbench
http://www.mysql.com/why-mysql/benchmarks/