sysbench介绍
源码地址:https://github.com/akopytov/sysbench
sysbench is a scriptable multi-threaded benchmark tool based on LuaJIT. It is most frequently used for database benchmarks, but can also be used to create arbitrarily complex workloads that do not involve a database server.
sysbench comes with the following bundled benchmarks:
oltp_*.lua
: a collection of OLTP-like database benchmarks
fileio
: a filesystem-level benchmark
cpu
: a simple CPU benchmark
memory
: a memory access benchmark
threads
: a thread-based scheduler benchmark
mutex
: a POSIX mutex benchmark
简单的说,sysbench是一个基于Lua即时编译器(http://luajit.org/luajit.html )实现的多线程基准测试工具。它被频繁用于数据库基准测试,除此之外,它也可以被用于进行其他复杂的负载测试,比如fileio,cpu,memory等。
本文主要介绍 sysbench fileio
基准测试的使用。
sysbench安装
sysbench支持多个平台使用,但是因为平台不一样,支持的特性会不一样,比如linux系统上支持的特性 --file-extra-flags=direct
(文件读写模式改成direct),在mac上就不支持了,会提示如下内容。
Extra file open flags: directio
FATAL: --file-extra-flags=direct is not supported on this platform.
ubuntu
:apt-get install sysbench
mac
:brew install sysbench
linux
: yum -y install sysbench
sysbench fileio 测试
1.测试目标
主要利用sysbench的fileio模块对服务器的rndrd(随机读)、rndwr(随机写)、rndrw(随机读写)性能进行压测,查看当前数据库部署在A服务器和B服务器之间的性能差异。
Notes:英文rnd
是random的缩写,rd
是read的缩写,wr
是write的缩写,rw
是read and write的缩写。
2.生成测试文件
sysbench --num-threads=16 --max-requests=0 --max-time=120 --file-num=128 --file-block-size=16384 --test=fileio --file-total-size=10G --file-test-mode=rndrw prepare
3.执行测试
sysbench --num-threads=16 --max-requests=0 --max-time=120 --file-num=128 --file-block-size=16384 --test=fileio --file-total-size=10G --file-test-mode=rndrw run
下图为测试结果。
图中r/s, w/s, rMiB/s, wMiB/s:分别表示每秒读写次数和每秒读写数据量,其中MiB/s和MB/s的换算如下
100 MiB/s = 1024 * 1024 * 100/(1000 * 1000) MB/s= 104.8576 MB/s
100 MB/s = 1000 * 1000 * 100/(1024 * 1024) MiB/s = 95.367431640625 MiB/s
图片数据来自 https://toolstud.io/data/bandwidth.php?compare=network&speed=100&speed_unit=MiB%2Fs ,另外推荐收藏关于硬盘IOPS单位转换的一个网站:https://www.wintelguy.com/iops-mbs-gbday-calc.pl
命令参数介绍
–file-num 生成测试的文件数
–file-block-size 文件块的大小
–file-total-size 生成测试文件总大小(test_file.0+…+test_file.n)
–file-test-mode 文件测试内容,包含seqwr、seqrewr、seqrd、rndrd、rndwr、rndrw
–max-time 测试时间
–num-threads 测试线程数
其他参数介绍可通过sysbench fileio help
命令查看
fileio options:
--file-num=N number of files to create [128]
--file-block-size=N block size to use in all IO operations [16384]
--file-total-size=SIZE total size of files to create [2G]
--file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
--file-io-mode=STRING file operations mode {sync,async,mmap} [sync]
--file-extra-flags=[LIST,...] list of additional flags to use to open files {sync,dsync,direct} []
--file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100]
--file-fsync-all[=on|off] do fsync() after each write operation [off]
--file-fsync-end[=on|off] do fsync() at the end of test [on]
--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]
--file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]
--file-rw-ratio=N reads/writes ratio for combined test [1.5]