MySQL 常用工具sysbench/fio/tpcc等测试

为什么要压力测试
采购新设备,评估新设备性能
开发新项目,评估数据库容量
新系统上线前,预估/模拟数据库负载
更换数据库版本,评估性能变化

关注指标 

CPU
%wait,%user,%sys
内存
只内存读写,不产生swap
IO
IOPS、 iowait、 svctm、 %util
数据库
TPS/TpmC、吞吏量(QPS)、响应时长、 InnoDB指标
影响因素
硬件
– CPU(省电模式、超线程、多核)
– 内存(镜像模式、 xen内核限制可用总内存大小)
– 阵列卡(BBU、 CACHE、条带、读写策略、 FW)
– 硬盘(SSD/SAS)
系统
– 内核参数(tcp相关)
– 文件系统
– IO调度器
MySQL
– TRANSACTION ISOLATION LEVEL
– Buffer pool
– Concurrency thread
– Redo log
– Binlog sync
– innodb_flush_log_at_trx_commit
----
可靠性测试
模拟意外事件
– 断电(硬件冷重启)
– RESET(硬件热重启)
– 阵列卡掉线
– 磁盘掉线
– REBOOT(系统重启)
– 正常关闭服务(kill -TERM)
– 异常关闭服务(kill -9)
– 磁盘空间满
– 删除文件
– 破坏性修改已打开文件
– …
长期极限高压
– 持续数小时、数天、数周运行高负载计算、 IO任务
– 考验服务器在高压下的性能波劢情况
– 考验硬件设备在高压下的稳定性表现
模拟恶劣环境
– 供电不稳
– 通风冷却不好
– 湿气大、灰尘多

注意事项
只在本地加压
压测数据量小
压测时间过短
压测模式太少
压力负载过大或过小
每轮测试完毕要净化环境
测试工具 sysbench,tpcc-mysql

# unzip sysbench-0.5.zip
yum install automake libaio libaio-devel  libtool -y

-----LOAD,CPU,QPS,TPS,CONNECT,IO,NET/IN,NET/OUT
[root@mysql5635 proc]# more loadavg 
0.00 0.01 0.05 1/221 8408
[root@mysql5635 proc]# cat /proc/cpuinfo
tar xvfz sysbench-0.4.12-1.1.tgz  
./autogen.sh
./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib && make && make install
--cpu性能测试
./sysbench --help
./sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
[root@mysql5635 sysbench]# ls /usr/local/mysql/lib/|grep libmysqlclient.so.18
libmysqlclient.so.18
libmysqlclient.so.18.1.0
[root@mysql5635 sysbench]# echo "/usr/local/mysql/lib" >>/etc/ld.so.conf
[root@mysql5635 sysbench]# ldconfig
drivers/mysql/libsbmysql.a -L/usr/local/mysql/lib -lmysqlclient_r scripting/lua/src/liblua.a -ldl -lrt -laio -lm -pthread
/usr/bin/ld: cannot find -lmysqlclient_r

fileio - 文件 I/O测试
cpu - CPU系能测试
memory - 内存功能速度测试
threads - 线程子系统系能测试
mutex - 互斥性能测试

运行
– sysbench --test=[mode] [other_options] prepare
– sysbench --test=[mode] [other_options] run
– sysbench --test=[mode] [other_options] cleanup
通用基准
– 最大请求数:5,000,000
– 并发线程数:8 ~ 512
基准 – OLTP
– mode=complex
– engine=innodb
– oltp-table-size=100,000,000
sysbench支持以下几种测试模式:
1、CPU运算性能
2、磁盘IO性能
3、调度程序性能
4、内存分配及传输速度
5、POSIX线程性能
6、数据库性能(OLTP基准测试)

测试用例

初始化测试库环境(总共10个测试表,每个表 100000 条记录,填充随机生成的数据)

./sysbench --mysql-host=127.0.0.1 --mysql-port=3317 --mysql-user=tpcc --mysql-password=*** \
 --test=tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=100000 --rand-init=on prepare
--test=tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
--oltp_tables_count=10 表示会生成 10 个测试表
--oltp-table-size=100000 表示每个测试表填充数据量为 100000 
--rand-init=on 表示每个测试表都是用随机数据来填充的
真实测试场景中,数据表建议不低于10个,单表数据量不低于500万行,当然了,要视服务器硬件配置而定。如果是配备了SSD或者PCIE SSD这种高IOPS设备的话,则建议单表数据量最少不低于1亿行。

 在上面初始化数据参数的基础上,再增加一些参数,即可开始进行测试了:

./sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=tpcc \
--mysql-password=**** --test=tests/db/oltp.lua --oltp_tables_count=10 \
--oltp-table-size=10000000 --num-threads=8 --oltp-read-only=off \
--report-interval=10 --rand-type=uniform --max-time=3600 \
 --max-requests=0 --percentile=99 run >> /tmp/2017080101.log
--num-threads=8 表示发起 8个并发连接
--oltp-read-only=off 表示不要进行只读测试,也就是会采用读写混合模式测试
--report-interval=10 表示每10秒输出一次测试进度报告
--rand-type=uniform 表示随机类型为固定模式,其他几个可选随机模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
--max-time=120 表示最大执行时长为 120秒
--max-requests=0 表示总请求数为 0,因为上面已经定义了总执行时长,所以总请求数可以设定为 0;也可以只设定总请求数,不设定最大执行时长
--percentile=99 表示设定采样比例,默认是 95%,即丢弃1%的长请求,在剩余的99%里取最大值
即:模拟 对10个表并发OLTP测试,每个表1000万行记录,持续压测时间为 1小时。
真实测试场景中,建议持续压测时长不小于30分钟,否则测试数据可能不具参考意义。

--oltp测试
--创建db

mysql> create database sbtest;

/data/soft/sysbench-0.5/sysbench/sysbench --test=/data/soft/sysbench-0.5/sysbench/tests/db/oltp.lua --oltp-table-size=5000000 \
--mysql-table-engine=innodb --mysql-user=system --mysql-password=**** --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=sbtest \
--max-requests=0 --max-time=600 --oltp-tables-count=10 --reportinterval=10 --oltp-read-only=off --num_threads=8 prepare

/data/soft/sysbench-0.5/sysbench/sysbench --test=/data/soft/sysbench-0.5/sysbench/tests/db/oltp.lua --oltp-table-size=5000000 \
--mysql-table-engine=innodb --mysql-user=system --mysql-password=****  --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=sbtest \
--max-requests=0 --max-time=600 --oltp-tables-count=10 --reportinterval=10 --oltp-read-only=off --num_threads=8 run >> /home/mysql/sysbench_20180806.log

测试结果解读如下:

[root@mysql5635 sysbench]# cat /home/mysql/sysbench.log
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 8
Report intermediate results every 10 second(s)
Random number generator seed is 0 and will be ignored


Threads started!
-- 每10秒钟报告一次测试结果,tps、每秒读、每秒写、99%以上的响应时长统计
[  10s] threads: 8, tps: 194.81, reads/s: 2737.20, writes/s: 780.05, response time: 206.36ms (99%)
[  20s] threads: 8, tps: 213.60, reads/s: 2991.02, writes/s: 856.40, response time: 176.82ms (99%)
[  30s] threads: 8, tps: 233.90, reads/s: 3274.61, writes/s: 934.00, response time: 111.08ms (99%)
[  40s] threads: 8, tps: 224.40, reads/s: 3141.18, writes/s: 899.19, response time: 87.77ms (99%)
[  50s] threads: 8, tps: 229.70, reads/s: 3215.82, writes/s: 916.01, response time: 138.09ms (99%)
[  60s] threads: 8, tps: 238.98, reads/s: 3346.58, writes/s: 957.24, response time: 70.88ms (99%)
[  70s] threads: 8, tps: 225.50, reads/s: 3156.95, writes/s: 901.19, response time: 97.78ms (99%)
[  80s] threads: 8, tps: 232.51, reads/s: 3255.48, writes/s: 931.25, response time: 105.51ms (99%)
[  90s] threads: 8, tps: 230.79, reads/s: 3230.76, writes/s: 921.56, response time: 117.30ms (99%)
[ 100s] threads: 8, tps: 232.91, reads/s: 3259.58, writes/s: 932.15, response time: 121.99ms (99%)
[ 110s] threads: 8, tps: 244.60, reads/s: 3422.53, writes/s: 979.41, response time: 80.64ms (99%)
[ 120s] threads: 8, tps: 234.39, reads/s: 3284.13, writes/s: 936.05, response time: 87.45ms (99%)
OLTP test statistics:
    queries performed:
        read:                            383124-- 读总数
        write:                           109464-- 写总数
        other:                           54732-- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
        total:                           547320-- 全部总数
    transactions:                        27366  (227.99 per sec.)-- 总事务数(每秒事务数)
    deadlocks:                           0      (0.00 per sec.)-- 发生死锁总数
    read/write requests:                 492588 (4103.90 per sec.)-- 读写总数(每秒读写次数)
    other operations:                    54732  (455.99 per sec.)-- 其他操作总数(每秒其他操作次数)

General statistics:-- 一些统计结果
    total time:                          120.0291s-- 总耗时
    total number of events:              27366- 共发生多少事务数
    total time taken by event execution: 959.7161s-- 所有事务耗时相加(不考虑并行因素)
    response time:-- 响应时长统计
         min:                                  5.35ms-- 最小耗时
         avg:                                 35.07ms-- 平均耗时
         max:                                455.91ms-- 最长耗时
         approx.  99 percentile:             116.12ms-- 超过99%平均耗时

Threads fairness:
    events (avg/stddev):           3420.7500/15.36
    execution time (avg/stddev):   119.9645/0.02

--获取数据

sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=system --mysql-password=**** --test=tests/db/oltp.lua --oltp_tables_count=3 \
--oltp-table-size=1000 --rand-init=on prepare
sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=system --mysql-password='****' --test=tests/db/oltp.lua --oltp_tables_count=3 \
--oltp-table-size=1000 --num-threads=8 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=120 --max-requests=0 \
--percentile=99 run >> /home/mysql/sysbench.log

----20180905 浪潮服务器测试

# unzip sysbench-0.5.zip
# yum install automake libaio libaio-devel  libtool -y
# ./autogen.sh
# ./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib && make && make install
drv_mysql.c:37:19: fatal error: mysql.h: No such file or directory
# yum install mysql-community-devel
# ./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/include/mysql && make && make install

# echo "export PATH=$PATH:/usr/local/sysbench/bin/">>/etc/profile 
# source /etc/profile
[root@mysql1 sysbench-0.5]# sysbench

sysbench --test=/usr/local/sysbench/share/sysbench/oltp.lua --oltp-table-size=5000000 \
--mysql-table-engine=innodb --mysql-user=system --mysql-password=**** --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=sbtest \
--max-requests=0 --max-time=600 --oltp-tables-count=10 --reportinterval=10 --oltp-read-only=off --num_threads=8 prepare

sysbench --test=/usr/local/sysbench/share/sysbench/oltp.lua --oltp-table-size=5000000 \
--mysql-table-engine=innodb --mysql-user=system --mysql-password=**** --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=sbtest \
--max-requests=0 --max-time=600 --oltp-tables-count=10 --reportinterval=10 --oltp-read-only=off --num_threads=8 run >> /home/mysql/sysbench_20180906.log

sysbench --test=/usr/local/sysbench/share/sysbench/oltp.lua --oltp-table-size=5000000 \
--mysql-table-engine=innodb --mysql-user=system --mysql-password=***** --mysql-port=3306 --mysql-host=127.0.0.1 --mysql-db=sbtest \
--max-requests=0 --max-time=600 --oltp-tables-count=10 --reportinterval=10 --oltp-read-only=off --num_threads=8 cleanup

--20190403

[root@localhost sysbench-0.5]# sysbench
sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
[root@localhost sysbench-0.5]# ll /usr/local/mysql/lib/libmysqlclient.so.20
lrwxrwxrwx. 1 mysql mysql 25 Apr  3 15:37 /usr/local/mysql/lib/libmysqlclient.so.20 -> libmysqlclient.so.20.3.11
[root@localhost sysbench-0.5]# ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20

tpcc--mysql--去掉外键,添加主键自增

https://github.com/yejr/tpcc-mysql-autoinc-pk
[root@mysql1 soft]# unzip tpcc-mysql-autoinc-pk-master.zip
[root@mysql1 tpcc-mysql-autoinc-pk-master]# cd src/
[root@mysql1 src]# make
cc -w -O2 -g -I. `mysql_config --include`  -c load.c
/bin/sh: mysql_config: 未找到命令
load.c:18:19: 致命错误:mysql.h:没有那个文件或目录
load.c:18:19: error: mysql.h: No such file or directory
[root@hongquan1 src]# cp /usr/local/mysql/include/mysql.h .
[root@hongquan1 src]# ln -s /usr/local/mysql/bin/mysql /usr/bin
[root@hongquan1 src]# make
cc -w -O2 -g -I. `mysql_config --include`  -c load.c
/bin/sh: mysql_config: command not found
[root@hongquan1 src]# export PATH=/usr/local/mysql/bin:$PATH
[root@hongquan1 src]# make
[root@hongquan1 src]# cd ..
[root@hongquan1 tpcc-mysql-autoinc-pk-master]# ll
total 268
-rw-r--r-- 1 root root   1621 Mar 21  2017 add_fkey_idx.sql
-rw-r--r-- 1 root root   6457 Mar 21  2017 create_table-autoinc-pk.sql
-rw-r--r-- 1 root root    477 Mar 21  2017 load.sh
-rw-r--r-- 1 root root    851 Mar 21  2017 README
-rw-r--r-- 1 root root   5534 Mar 21  2017 README.md
-rw-r--r-- 1 root root   1602 Mar 21  2017 run_tpcc.sh
drwxr-xr-x 2 root root   4096 Mar 21  2017 schema2
drwxr-xr-x 5 root root   4096 Mar 21  2017 scripts
drwxr-xr-x 2 root root   4096 Aug 13 10:10 src
-rwxr-xr-x 1 root root  62899 Aug 13 10:10 tpcc_load
-rw-r--r-- 1 root root   2193 Mar 21  2017 tpcc_load_parallel.sh
-rwxr-xr-x 1 root root 157354 Aug 13 10:10 tpcc_start
[root@mysql1 tpcc-mysql-autoinc-pk-master]# chown -R mysql:mysql /data/soft/tpcc-mysql-autoinc-pk-master
[mysql@mysql1 ~]$ mysqladmin -usystem -****' -h127.0.0.1 -P3306 create tpcc
[mysql@mysql1 ~]$ mysql -usystem -p'mysql' -h127.0.0.1 -P3306 -f tpcc < create_table-autoinc-pk.sql
加载数据
[root@mysql1 tpcc-mysql-autoinc-pk-master]# ./tpcc_load 192.168.19.87:3306 tpcc system "*****" 10
[root@mysql1 tpcc-mysql-autoinc-pk-master]# time ./tpcc_start -h 192.168.19.87 -P 3306 -d tpcc -usystem -****' -w 10 -c 32 -r 120 -l 600 -f tpcc_mysql_2018081301

--tpcc-mysql
http://blog.chinaunix.net/uid-26896862-id-3188313.html
--tpcc使用说明
下载TPCC-MySQL

[root@12crac1 software]# yum install bzr -y
[root@12crac1 software]# bzr branch lp:~percona-dev/perconatools/tpcc-mysql  
 You have not informed bzr of your Launchpad ID, and you must do this to
write to Launchpad or access private data.  See "bzr help launchpad-login".
Branched 48 revision(s). 
[root@12crac1 software]# export PATH=/usr/local/mysql/bin:$PATH
[root@12crac1 software]# cd tpcc-mysql/src/
[root@12crac1 src]# make
cc -w -O2 -g -I. `mysql_config --include`  -c load.c
[root@12crac1 src]# cd ..
[root@12crac1 tpcc-mysql]# ll          
-rwxr-xr-x 1 root root  61199 Mar 30 23:38 tpcc_load--用于初始化数据
-rwxr-xr-x 1 root root 155934 Mar 30 23:38 tpcc_start--用于执行基准测试

基本配置
[root@12crac1 ~]# su - mysql
[mysql@12crac1 ~]$ cd /data/software/tpcc-mysql/
[mysql@12crac1 src]$ mysqladmin create tpcc
mysql> create database tpcc;
– create_table.sql - 创建数据表
– add_fkey_idx.sql – 创建索引及外键
[mysql@12crac1 tpcc-mysql]$ mysql -h 127.0.0.1 -usystem -pmysql tpcc < create_table.sql 
[mysql@12crac1 tpcc-mysql]$ mysql -h 127.0.0.1 -usystem -pmysql tpcc < add_fkey_idx.sql 
mysql> show tables;
+----------------+
| Tables_in_tpcc |
+----------------+
| customer       |
| district       |
| history        |
| item           |
| new_orders     |
| order_line     |
| orders         |
| stock          |
| warehouse      |
初始化加载数据
– tpcc_load db_host db_name db_user db_passwd
db_warehouse_num
– 例如:tpcc_load localhost tpcc1000 user passwd 1000
运行OLTP测试
– ./tpcc_start -h localhost -d tpcc1000 -u root -p '***' -w 1000
-c 32 -r 120 -l 3600 -f ./tpcc_mysql_20120314
基准 - OLTP
– warehouse = 1000
– max connection = 8 ~ 512
– warm up = 120(s)
– run time/duration = 3600(s)
测试用例
./tpcc_start -h host -d db -u user -p passwd -w 500 -c 128 -r 120 -l 3600
-w warehose/仓库数
-c concurrent threads/并发线程
-r warmup/数据预热时长
-l during time/持续加压时长

[mysql@12crac1 tpcc-mysql]$ ./tpcc_load 127.0.0.1:3306 tpcc system "****" 10
./tpcc_load: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
[root@12crac1 tpcc-mysql]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
--初始化数据

./tpcc_load 127.0.0.1:3306 tpcc system "***" 2
./tpcc_start -h 127.0.0.1 -d tpcc -usystem -p "***" -w 2 -c 2 -r 100 -l 300  > tpcc.out

[root@12crac1 tpcc-mysql]# vim load.sh
介绍一下各个参数的用法
-h server_host:    服务器名
-P port :    端口号,默认为3306
-d database_name:    数据库名
-u mysql_user :    用户名
-p mysql_password :    密码
-w warehouses:    仓库的数量
-c connections :    线程数,默认为1
-r warmup_time :    热身时间,单位:s,默认为10s ,热身是为了将数据加载到内存。
-l running_time:    测试时间,单位:s,默认为20s--建议半个小时或一个小时 3600
-i report_interval:    指定生成报告间隔时长
-f report_file:    测试结果输出文件
[root@12crac1 tpcc-mysql]# ./tpcc_start -h 127.0.0.1 -d tpcc -usystem -p "***" -w 10 -c 10 -r 100 -l 300 -f /home/mysql/tpcc_mysql.log -t /home/mysql/tpcc_mysql.rtx
./tpcc_start -h 127.0.0.1 -d tpcc -usystem -p "***" -w 10 -c 10 -r 1200 -l 3600  > tpcc.out

sc--成功,lt--延迟,rt--重试,fl--失败
http://blog.chinaunix.net/uid-26896862-id-3563600.html
--tpc 输出详情
STOPPING THREADS..........

<Raw Results>
  [0] sc:33640  lt:5  rt:0  fl:0 
  [1] sc:33648  lt:0  rt:0  fl:0 
  [2] sc:3364  lt:0  rt:0  fl:0 
  [3] sc:3364  lt:0  rt:0  fl:0 
  [4] sc:3364  lt:0  rt:0  fl:0 
 in 300 sec.

<Raw Results2(sum ver.)>
  [0] sc:33640  lt:5  rt:0  fl:0 
  [1] sc:33648  lt:0  rt:0  fl:0 
  [2] sc:3364  lt:0  rt:0  fl:0 
  [3] sc:3364  lt:0  rt:0  fl:0 
  [4] sc:3364  lt:0  rt:0  fl:0 

<Constraint Check> (all must be [OK])
 [transaction percentage]
        Payment: 43.48% (>=43.0%) [OK]
   Order-Status: 4.35% (>= 4.0%) [OK]
       Delivery: 4.35% (>= 4.0%) [OK]
    Stock-Level: 4.35% (>= 4.0%) [OK]
 [response time (at least 90% passed)]
      New-Order: 99.99%  [OK]
        Payment: 100.00%  [OK]
   Order-Status: 100.00%  [OK]
       Delivery: 100.00%  [OK]
    Stock-Level: 100.00%  [OK]

<TpmC>
                 6729.000 TpmC
--TpmC 整体性能指标,本系统每分钟能够处理的订单数量,tpcc没有收集系统性能指标
                 
--使用gnuplot生成图表
[root@12crac1 mysql]# yum install -y gnuplot
[root@12crac1 mysql]# gnuplot
[root@12crac1 mysql]# rm -f /var/run/yum.pid
[root@12crac1 mysql]# yum install -y gnuplot-x11 
[root@12crac1 scripts]# chmod +x analyze.sh 
[root@12crac1 scripts]# ./analyze.sh /home/mysql/tpcc_mysql1.log /home/mysql/tpcc_20160331.res
Defined /home/mysql/tpcc_20160331.res
[root@12crac1 scripts]# pwd
/data/software/tpcc-mysql/scripts
[root@12crac1 mysql]# vim log.conf 
[root@12crac1 mysql]# more log.conf 
set terminal gif small size 480,360 #指定输出成gif图片,且图片大小为550×25
set output "tcpp.gif"    #指定输出gif图片的文件名
set title "MySQL Performance"    #图片标题
set style data lines    #显示网格
set xlabel "Time/s"    #X轴标题
set ylabel "Data"    #Y轴标题
set grid    #显示网格
plot \
"tpcc_20160331.res" using 1:2 title "Total throughput" with lines
运行生成tcpp.gif:
#cat log.conf | gnuplot
---20160415
./tpcc_start -h 127.0.0.1 -d tpcc -usystem -p "mysql" -w 10 -c 10 -r 100 -l 300  > tpcc.out
[root@12crac1 scripts]# ./analyze.sh /data/software/tpcc-mysql/tpcc.out >/home/mysql/tpcc_test.txt
[root@12crac1 mysql]# cat log.conf |gnuplot
Could not find/open font when opening font "arial", using internal non-scalable font
[root@12crac1 mysql]# more tpcc_test.txt 
1 1.403000
0 0.000000
fio在Linux系统下使用比较方便,iometer在window系统下使用比较方便,Orion是oracle的IO测试软件,可在没有安装oracle数据库的情况下模拟oracle数据库场景的读写。

--下载fio源码包
--检查aio依赖包

[root@12crac1 ~]# rpm -qa|grep aio
libaio-devel-0.3.107-10.el6.x86_64
libaio-0.3.107-10.el6.x86_64
[root@12crac1 software]# tar xvfz fio-2.1.10.tar.gz
[root@12crac1 fio-2.1.10]# ./configure 
[root@12crac1 fio-2.1.10]# make -j
[root@12crac1 fio-2.1.10]# ll |grep fio
-rwxr-xr-x 1 root root 3164335 Mar 30 22:48 fio
[root@12crac1 fio-2.1.10]# ./fio --help
fio-2.1.10
[root@12crac1 fio-2.1.10]# ./fio --cmdhelp
[root@12crac1 fio-2.1.10]# ./fio --enghelp
--output
--output-format=x
--crctest        Test speed of checksum functions
--cpuclock-test    Perform test/validation of CPU clock
--runtime        Runtime in seconds
[root@12crac1 fio-2.1.10]# ./fio -filename=/data/ -direct=1 -iodepth 1 -rw=read -ioengine=psync \
-bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest --output-format=json
fio: pid=0, err=21/file:filesetup.c:63, func=unlink, error=Is a directory
fio是用来对裸设备做测试的,所以你的-filename参数不能使用目录,而应该使用硬盘分区
fio是一个非常灵活的io测试工具
说明:
filename=/dev/sdb1       测试文件名称,通常选择需要测试的盘的data目录。
direct=1                 测试过程绕过机器自带的buffer。使测试结果更真实,是否使用directIO。
rw=randwrite             测试随机写的I/O
rw=randrw                测试随机写和读的I/O
bs=16k                   单次io的块文件大小为16k
bsrange=512-2048         同上,提定数据块的大小范围
size=5g    本次的测试文件大小为5g,以每次4k的io进行测试,每个线程写入数据量。
numjobs=30               本次的测试线程为30.
runtime=1000             测试时间为1000秒,如果不写则一直将5g文件分4k每次写完为止。
ioengine=psync           io引擎使用pync方式
rwmixwrite=30            在混合读写的模式下,写占30%
group_reporting          关于显示结果的,汇总每个进程的信息。
此外
lockmem=1g               只使用1g内存进行测试。
zero_buffers             用0初始化系统buffer。
nrfiles=8                每个进程生成文件的数量
-thread:使用pthread_create创建线程,另一种是fork创建进程。进程的开销比线程要大,一般都采用thread测试。

ios=所有group总共执行的IO数.
merge=总共发生的IO合并数.
ticks=Number of ticks we kept the disk busy.
io_queue=花费在队列上的总共时间.
util=磁盘利用率
[root@12crac1 fio-2.1.10]# ./fio -filename=/dev/sda -direct=1 -iodepth 1 -rw=read -ioengine=psync -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest --output-format=json
{
  "fio version" : "fio-2.1.10",
  "jobs" : [
    {
      "jobname" : "mytest",
      "groupid" : 0,
      "error" : 0,
      "read" : {
        "io_bytes" : 2159952,
        "bw" : 215973,
        "iops" : 13498,
        "runtime" : 10001,
        "slat" : {
          "min" : 0,
          "max" : 0,
          "mean" : 0.00,
          "stddev" : 0.00
....
[root@12crac1 fio-2.1.10]# ./fio -filename=/dev/sda -direct=1 -iodepth 1 -rw=read -ioengine=psync -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest
mytest: (g=0): rw=read, bs=16K-16K/16K-16K/16K-16K, ioengine=psync, iodepth=1
...
fio-2.1.10
Starting 10 processes
Jobs: 10 (f=10): [RRRRRRRRRR] [100.0% done] [240.5MB/0KB/0KB /s] [15.4K/0/0 iops] [eta 00m:00s]
mytest: (groupid=0, jobs=10): err= 0: pid=10322: Wed Mar 30 23:11:15 2016
  read : io=1931.7MB, bw=197775KB/s, iops=12360, runt= 10001msec
    clat (usec): min=75, max=95487, avg=767.47, stdev=1761.01
     lat (usec): min=77, max=95489, avg=777.35, stdev=1767.68
    clat percentiles (usec):
     |  1.00th=[  133],  5.00th=[  215], 10.00th=[  270], 20.00th=[  334],
     | 30.00th=[  382], 40.00th=[  430], 50.00th=[  486], 60.00th=[  564],
     | 70.00th=[  668], 80.00th=[  836], 90.00th=[ 1192], 95.00th=[ 1896],
     | 99.00th=[ 4832], 99.50th=[ 7328], 99.90th=[23680], 99.95th=[38144],
     | 99.99th=[60160]
    bw (KB  /s): min= 8399, max=32608, per=9.95%, avg=19677.21, stdev=5373.64
    lat (usec) : 100=0.12%, 250=7.92%, 500=44.10%, 750=23.21%, 1000=10.76%
    lat (msec) : 2=9.29%, 4=3.18%, 10=1.08%, 20=0.19%, 50=0.11%
    lat (msec) : 100=0.03%
  cpu          : usr=0.05%, sys=11.29%, ctx=133572, majf=0, minf=382
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=123622/w=0/d=0, short=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: io=1931.7MB, aggrb=197775KB/s, minb=197775KB/s, maxb=197775KB/s, mint=10001msec, maxt=10001msec

Disk stats (read/write):
  sda: ios=122254/23, merge=0/25, ticks=54655/70, in_queue=54000, util=95.92%

==20180823
wget http://brick.kernel.dk/snaps/fio-2.2.5.tar.gz
yum install libaio-devel

随机读:(可直接用,向磁盘写一个2G文件,10线程,随机读1分钟,给出结果)
fio -filename=/tmp/test_randread -direct=1 -iodepth 1 -thread -rw=randread -ioengine=psync -bs=16k -size=2G -numjobs=10 -runtime=60 -group_reporting -name=mytest
read 顺序读
write 顺序写
rw,readwrite 顺序混合读写
randwrite 随机写
randread 随机读
randrw 随机混合读写
./fio -filename=/dev/sda -direct=1 -iodepth 1 -rw=read -ioengine=psync -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest
./fio -filename=/dev/sda -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=70 -ioengine=psync -bs=16k -size=200G -numjobs=30 -runtime=100 -group_reporting -name=mytest1
./fio -filename=/data -direct=1 -iodepth 1 -rw=read -ioengine=psync -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest
./fio -filename=/data/ -direct=1 -iodepth 1 -rw=randrw -ioengine=psync -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest --output-format=json
./fio -filename=/data/ -direct=1 -iodepth 1 -rw=read -ioengine=psync -bs=16k -size=100G -numjob=10 -runtime=10 -group_reporting -name=mytest --output-format=json
--iops
[root@mysqlhq fio-2.2.5]# ./fio -filename=/dev/mapper/kylin-home -direct=1 -iodepth 1 -thread -rw=randrw -ioengine=psync -bs=16k -size=500m -numjobs=10 -runtime=10 -group_reporting -name=mytest --output-format=json

==118
[root@hongquan1 fio-2.2.5]# ./fio -filename=/dev/sda -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=70 -ioengine=psync -bs=16k -size=200G -numjobs=30 -runtime=100 -group_reporting -name=mytest1
mytest1: (g=0): rw=randrw, bs=16K-16K/16K-16K/16K-16K, ioengine=psync, iodepth=1
...
fio-2.2.5
Starting 30 threads
Jobs: 30 (f=30): [m(30)] [100.0% done] [495KB/223KB/0KB /s] [30/13/0 iops] [eta 00m:00s]  
mytest1: (groupid=0, jobs=30): err= 0: pid=1359: Thu Aug 23 16:16:29 2018
  read : io=153456KB, bw=1531.3KB/s, iops=95, runt=100218msec
    clat (usec): min=33, max=1776.9K, avg=230518.12, stdev=295161.54
     lat (usec): min=33, max=1776.9K, avg=230518.31, stdev=295161.57
    clat percentiles (usec):
     |  1.00th=[   52],  5.00th=[   82], 10.00th=[  119], 20.00th=[  290],
     | 30.00th=[28544], 40.00th=[83456], 50.00th=[144384], 60.00th=[203776],
     | 70.00th=[268288], 80.00th=[362496], 90.00th=[585728], 95.00th=[905216],
     | 99.00th=[1368064], 99.50th=[1449984], 99.90th=[1646592], 99.95th=[1712128],
     | 99.99th=[1777664]
    bw (KB  /s): min=    7, max=  677, per=3.92%, avg=60.01, stdev=46.19
  write: io=63520KB, bw=649029B/s, iops=39, runt=100218msec
    clat (usec): min=40, max=1726.6K, avg=199873.39, stdev=299754.56
     lat (usec): min=41, max=1726.6K, avg=199874.13, stdev=299754.51
    clat percentiles (usec):
     |  1.00th=[   56],  5.00th=[   73], 10.00th=[   87], 20.00th=[  127],
     | 30.00th=[  193], 40.00th=[  354], 50.00th=[16320], 60.00th=[179200],
     | 70.00th=[248832], 80.00th=[342016], 90.00th=[552960], 95.00th=[872448],
     | 99.00th=[1384448], 99.50th=[1482752], 99.90th=[1695744], 99.95th=[1728512],
     | 99.99th=[1728512]
    bw (KB  /s): min=    7, max=  186, per=5.75%, avg=36.39, stdev=23.70
    lat (usec) : 50=0.65%, 100=8.68%, 250=14.30%, 500=5.25%, 750=1.63%
    lat (usec) : 1000=0.49%
    lat (msec) : 2=0.69%, 4=0.68%, 10=1.39%, 20=1.03%, 50=4.08%
    lat (msec) : 100=6.75%, 250=22.73%, 500=18.98%, 750=6.22%, 1000=2.55%
    lat (msec) : 2000=3.90%
  cpu          : usr=0.00%, sys=0.01%, ctx=13467, majf=0, minf=5
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=9591/w=3970/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: io=153456KB, aggrb=1531KB/s, minb=1531KB/s, maxb=1531KB/s, mint=100218msec, maxt=100218msec
  WRITE: io=63520KB, aggrb=633KB/s, minb=633KB/s, maxb=633KB/s, mint=100218msec, maxt=100218msec

Disk stats (read/write):
  sda: ios=10366/4808, merge=2971/339, ticks=2457713/996312, in_queue=3471461, util=100.00%
==226
Starting 30 threads
Jobs: 30 (f=30): [m(30)] [0.0% done] [2157KB/1326KB/0KB /s] [134/82/0 iops] [eta 04d:15h:34m:27s]
mytest1: (groupid=0, jobs=30): err= 0: pid=15910: Thu Aug 23 17:03:17 2018
  read : io=1174.1MB, bw=11987KB/s, iops=749, runt=100365msec
    clat (usec): min=18, max=1509.4K, avg=39328.95, stdev=97965.98
     lat (usec): min=18, max=1509.4K, avg=39329.08, stdev=97965.99
    clat percentiles (usec):
     |  1.00th=[   27],  5.00th=[   38], 10.00th=[   85], 20.00th=[ 5216],
     | 30.00th=[ 8512], 40.00th=[11584], 50.00th=[16064], 60.00th=[22144],
     | 70.00th=[30592], 80.00th=[43776], 90.00th=[74240], 95.00th=[124416],
     | 99.00th=[497664], 99.50th=[700416], 99.90th=[1335296], 99.95th=[1449984],
     | 99.99th=[1466368]
    bw (KB  /s): min=   10, max= 1238, per=3.81%, avg=456.55, stdev=290.27
  write: io=494432KB, bw=4926.4KB/s, iops=307, runt=100365msec
    clat (usec): min=57, max=852603, avg=1574.68, stdev=19490.91
     lat (usec): min=57, max=852604, avg=1575.08, stdev=19490.91
    clat percentiles (usec):
     |  1.00th=[   64],  5.00th=[   70], 10.00th=[   75], 20.00th=[   82],
     | 30.00th=[   89], 40.00th=[   98], 50.00th=[  111], 60.00th=[  139],
     | 70.00th=[  426], 80.00th=[  636], 90.00th=[ 1624], 95.00th=[ 2448],
     | 99.00th=[ 6368], 99.50th=[19840], 99.90th=[346112], 99.95th=[464896],
     | 99.99th=[659456]
    bw (KB  /s): min=    8, max=  773, per=4.15%, avg=204.32, stdev=134.39
    lat (usec) : 20=0.01%, 50=5.23%, 100=14.37%, 250=8.37%, 500=2.12%
    lat (usec) : 750=2.72%, 1000=1.01%
    lat (msec) : 2=2.93%, 4=4.07%, 10=13.03%, 20=15.51%, 50=18.59%
    lat (msec) : 100=7.23%, 250=3.06%, 500=1.04%, 750=0.40%, 1000=0.16%
    lat (msec) : 2000=0.16%
  cpu          : usr=0.02%, sys=0.05%, ctx=106098, majf=0, minf=7
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=75194/w=30902/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: io=1174.1MB, aggrb=11987KB/s, minb=11987KB/s, maxb=11987KB/s, mint=100365msec, maxt=100365msec
  WRITE: io=494432KB, aggrb=4926KB/s, minb=4926KB/s, maxb=4926KB/s, mint=100365msec, maxt=100365msec

Disk stats (read/write):
  sda: ios=75535/30918, merge=1152/5, ticks=2952491/48125, in_queue=3007268, util=100.00%
==145
mytest1: (groupid=0, jobs=30): err= 0: pid=29172: Thu Aug 23 17:27:52 2018
  read : io=1471.8MB, bw=14105KB/s, iops=881, runt=106844msec
    clat (usec): min=19, max=8208.3K, avg=30723.67, stdev=167017.33
     lat (usec): min=19, max=8208.3K, avg=30723.84, stdev=167017.33
    clat percentiles (usec):
     |  1.00th=[   25],  5.00th=[   29], 10.00th=[   34], 20.00th=[   45],
     | 30.00th=[   61], 40.00th=[  118], 50.00th=[  676], 60.00th=[ 6432],
     | 70.00th=[17024], 80.00th=[38144], 90.00th=[80384], 95.00th=[120320],
     | 99.00th=[244736], 99.50th=[428032], 99.90th=[1728512], 99.95th=[5079040],
     | 99.99th=[6193152]
    bw (KB  /s): min=    1, max= 1937, per=4.38%, avg=617.23, stdev=324.41
  write: io=625072KB, bw=5850.4KB/s, iops=365, runt=106844msec
    clat (usec): min=59, max=8208.4K, avg=3492.90, stdev=64545.70
     lat (usec): min=60, max=8208.4K, avg=3517.20, stdev=64601.41
    clat percentiles (usec):
     |  1.00th=[   69],  5.00th=[   80], 10.00th=[   90], 20.00th=[  113],
     | 30.00th=[  219], 40.00th=[  450], 50.00th=[  494], 60.00th=[  548],
     | 70.00th=[  700], 80.00th=[  988], 90.00th=[ 2160], 95.00th=[ 3984],
     | 99.00th=[35584], 99.50th=[123392], 99.90th=[552960], 99.95th=[667648],
     | 99.99th=[1003520]
    bw (KB  /s): min=    1, max= 1052, per=4.54%, avg=265.60, stdev=152.50
    lat (usec) : 20=0.01%, 50=17.05%, 100=14.41%, 250=8.37%, 500=8.76%
    lat (usec) : 750=8.01%, 1000=3.49%
    lat (msec) : 2=4.48%, 4=3.92%, 10=5.43%, 20=5.85%, 50=8.23%
    lat (msec) : 100=6.78%, 250=4.44%, 500=0.41%, 750=0.11%, 1000=0.04%
    lat (msec) : 2000=0.13%, >=2000=0.06%
  cpu          : usr=0.19%, sys=0.22%, ctx=133273, majf=0, minf=19
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=94192/w=39067/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: io=1471.8MB, aggrb=14105KB/s, minb=14105KB/s, maxb=14105KB/s, mint=106844msec, maxt=106844msec
  WRITE: io=625072KB, aggrb=5850KB/s, minb=5850KB/s, maxb=5850KB/s, mint=106844msec, maxt=106844msec

Disk stats (read/write):
  sda: ios=94438/39072, merge=49/0, ticks=2855388/142114, in_queue=2997516, util=95.88%
posted @ 2019-08-06 16:13  春困秋乏夏打盹  阅读(2131)  评论(0编辑  收藏  举报