任务:在Linux下用fio测试工具(Google搜索fio benchmark)测试一个U盘的性能,U盘上不要放任何数据。
通过这个任务,了解fio的具体使用,各个参数的具体含义,并且了解U盘的随机和顺序读写。
笔记:
首先安装fio工具:
$ wget http://brick.kernel.dk/snaps/fio-2.0.7.tar.gz
$ tar -zxvf fio-2.0.7.tar.gz
$ cd fio-2.0.7
$ make
$ make install
命令参数:
#filename:目标盘符/测试设备:filename=/dev/sdb4(可用lsblk命令查询usb对应dev下的节点)
#direct: 测试过程绕过机器自带的buffer,使测试结果更真实。
#I/O type:rw=Read(顺序读)/write(顺序写)/randread(随机读)/randwrite(随机写)/randrw(随机写和读)
#Block Size:单次IO的块文件大小,bs=4k,4k是主流,8k是Mysql和Oracle,16K是MysqlInnodb
#I/O size:总共要读写的数据大小,size=10G
#Num threads:创建多少进程/线程来并发执行,numjobs=64
#Runtime:测试运行时间,runtime=10,单位为s
#group_reporting:关于显示结果的,汇总每个进程的信息。
#ioengine:io引擎,处理io的方式,包括sync,pync,vsync,libaio 等,目前使用最广泛的是 libaio。
具体区别见http://www.cnblogs.com/cloudphoenix/p/6542909.html
#iodepth:测试的队列深度,队列深度表示控制器可同时发送给被测设备的指令数目。默认为1。
#Num files: 表示负载将分发到几个文件中。例如:nrfiles=8
#数据填充方式: 当进行数据写入时,可选择写入数据的形式。此选项可选三种模式,分别为重复填充(填全0)、伪随机填充(填伪随机数)、随机填充(先生成随机数,再填充)。
#percentage_random:随机和顺序比率;例如:percentage_random=80,80%的随机
# time_based :决定脚本的运行时间,即使 file 已被完全读写或写完,也要执行完runtime 规定的时间。它是通过循环执行相同的负载来实现的。例如:time_based
结果分析:
#io:总的输入输出量 bw:带宽 KB/s iops:每秒钟的IO数 runt:总运行时间
#slat:submission latency提交延迟。io提交到内核需要的时间
#clat:completion latency完成延迟。io提交到内核后一直到io完成的间隔时间,不包括slat
# clat percentiles:描述IO整体延迟latency distribution,为不同百分比IO的clat。
可以根据这些百分比数来绘制图形,从整体上分析IO系统的IO延时。这是非常有用的一个用来描述IO系统延时情况的指标
#lat (msec):延迟(毫秒) msec: 毫秒 usec: 微秒
# IO depths:这个iodepth设置是用来控制在任意给定时刻,有多少个IO被提交给OS。这个参数完全是应用端来设置
submit:表明fio一次提交多少个IO
complete:一次完成多少个IO
例子:
1、顺序读
$ sudo fio -filename=/dev/sdb4 -direct=1 -iodepth 1 -thread -rw=read -ioengine=psync -bs=16k -size=200G -numjobs=30 -runtime=100 -group_reporting -name=mytes
结果:
mytes: (g=0): rw=read, bs=16K-16K/16K-16K/16K-16K, ioengine=psync, iodepth=1
...
fio-2.1.10
Starting 30 threads
Jobs: 30 (f=30): [RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR] [100.0% done] [20288KB/0KB/0KB /s] [1268/0/0 iops] [eta 00m:00s]
mytes: (groupid=0, jobs=30): err= 0: pid=4202: Sat May 13 13:21:18 2017
read : io=1956.1MB, bw=20034KB/s, iops=1252, runt=100024msec
clat (msec): min=1, max=109, avg=23.95, stdev= 6.36
lat (msec): min=1, max=109, avg=23.95, stdev= 6.36
clat percentiles (usec):
| 1.00th=[11200], 5.00th=[14016], 10.00th=[16512], 20.00th=[19840],
| 30.00th=[21888], 40.00th=[23168], 50.00th=[23680], 60.00th=[24448],
| 70.00th=[25728], 80.00th=[27008], 90.00th=[29568], 95.00th=[33536],
| 99.00th=[47360], 99.50th=[54016], 99.90th=[67072], 99.95th=[74240],
| 99.99th=[90624]
bw (KB /s): min= 415, max= 806, per=3.33%, avg=668.08, stdev=41.12
lat (msec) : 2=0.01%, 4=0.01%, 10=0.34%, 20=19.86%, 50=79.05%
lat (msec) : 100=0.74%, 250=0.01%
cpu : usr=0.01%, sys=0.05%, ctx=126086, majf=0, minf=120
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=125243/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=1956.1MB, aggrb=20034KB/s, minb=20034KB/s, maxb=20034KB/s, mint=100024msec, maxt=100024msec
Disk stats (read/write):
sdb: ios=23474/0, merge=85162/0, ticks=669312/0, in_queue=680060, util=100.00%
2、顺序写
$ sudo fio -filename=/dev/sdb4 -direct=1 -iodepth 1 -thread -rw=write -ioengine=psync -bs=16k -size=20G -numjobs=30 -runtime=100 -group_reporting -name=mytes
结果:
mytes: (g=0): rw=write, bs=16K-16K/16K-16K/16K-16K, ioengine=psync, iodepth=1
...
fio-2.1.10
Starting 30 threads
Jobs: 30 (f=30): [WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW] [0.1% done] [0KB/0KB/0KB /s] [0/0/0 iops] [eta 01d:01h:13m:41s]//?????0.1%done
mytes: (groupid=0, jobs=30): err= 0: pid=4545: Sat May 13 13:39:57 2017
write: io=700608KB, bw=6895.2KB/s, iops=430, runt=101609msec
clat (msec): min=10, max=3688, avg=69.59, stdev=293.26
lat (msec): min=10, max=3688, avg=69.59, stdev=293.26
clat percentiles (msec):
| 1.00th=[ 20], 5.00th=[ 23], 10.00th=[ 29], 20.00th=[ 36],
| 30.00th=[ 38], 40.00th=[ 39], 50.00th=[ 41], 60.00th=[ 43],
| 70.00th=[ 44], 80.00th=[ 47], 90.00th=[ 55], 95.00th=[ 82],
| 99.00th=[ 260], 99.50th=[ 3589], 99.90th=[ 3589], 99.95th=[ 3589],
| 99.99th=[ 3621]
bw (KB /s): min= 4, max= 487, per=4.75%, avg=327.27, stdev=104.30
lat (msec) : 20=1.04%, 50=85.64%, 100=9.04%, 250=2.94%, 500=0.65%
lat (msec) : >=2000=0.69%
cpu : usr=0.01%, sys=0.02%, ctx=44941, majf=0, minf=0
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=0/w=43788/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):
WRITE: io=700608KB, aggrb=6895KB/s, minb=6895KB/s, maxb=6895KB/s, mint=101609msec, maxt=101609msec
Disk stats (read/write):
sdb: ios=0/8281, merge=0/29873, ticks=0/659780, in_queue=693188, util=99.97%
3、随机写
$ sudo fio -filename=/dev/sdb4 -direct=1 -iodepth 1 -thread -rw=randwrite -ioengine=psync -bs=16k -size=20G -numjobs=30 -runtime=100 -group_reporting -name=mytes
结果:
mytes: (g=0): rw=randwrite, bs=16K-16K/16K-16K/16K-16K, ioengine=psync, iodepth=1
...
fio-2.1.10
Starting 30 threads
Jobs: 1 (f=1): [______w_______________________] [4.6% done] [0KB/0KB/0KB /s] [0/0/0 iops] [eta 01h:12m:09s]
mytes: (groupid=0, jobs=30): err= 0: pid=4629: Sat May 13 13:45:30 2017
write: io=1072.0KB, bw=5222B/s, iops=0, runt=210182msec
clat (msec): min=12, max=178306, avg=69632.59, stdev=52464.42
lat (msec): min=12, max=178306, avg=69632.59, stdev=52464.42
clat percentiles (msec):
| 1.00th=[ 13], 5.00th=[ 50], 10.00th=[ 86], 20.00th=[16712],
| 30.00th=[16712], 40.00th=[16712], 50.00th=[16712], 60.00th=[16712],
| 70.00th=[16712], 80.00th=[16712], 90.00th=[16712], 95.00th=[16712],
| 99.00th=[16712], 99.50th=[16712], 99.90th=[16712], 99.95th=[16712],
| 99.99th=[16712]
bw (KB /s): min= 0, max= 4, per=4.07%, avg= 0.20, stdev= 0.76
lat (msec) : 20=1.49%, 50=2.99%, 100=7.46%, >=2000=88.06%
cpu : usr=0.00%, sys=0.00%, ctx=77, majf=0, minf=0
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=0/w=67/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):
WRITE: io=1072KB, aggrb=5KB/s, minb=5KB/s, maxb=5KB/s, mint=210182msec, maxt=210182msec
Disk stats (read/write):
sdb: ios=5/66, merge=0/0, ticks=92464/4525652, in_queue=4763880, util=100.00%
4、混合随机读写
$ sudo fio -filename=/dev/sdb4 -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=70 -ioengine=psync -bs=16k -size=20G -numjobs=30 -runtime=100 -group_reporting -name=mytes -ioscheduler=noop
#rwmixread=70 //读占70%
结果:
mytes: (g=0): rw=randrw, bs=16K-16K/16K-16K/16K-16K, ioengine=psync, iodepth=1
...
fio-2.1.10
Starting 30 threads
Jobs: 5 (f=5): [___m__mm___mm_________________] [5.1% done] [0KB/0KB/0KB /s] [0/0/0 iops] [eta 01h:01m:45s]
mytes: (groupid=0, jobs=30): err= 0: pid=4872: Sat May 13 13:51:46 2017
read : io=3904.0KB, bw=20113B/s, iops=1, runt=198759msec
clat (msec): min=1, max=116824, avg=7612.76, stdev=22139.72
lat (msec): min=1, max=116824, avg=7612.76, stdev=22139.72
clat percentiles (msec):
| 1.00th=[ 5], 5.00th=[ 19], 10.00th=[ 35], 20.00th=[ 41],
| 30.00th=[ 41], 40.00th=[ 41], 50.00th=[ 42], 60.00th=[ 44],
| 70.00th=[ 44], 80.00th=[ 47], 90.00th=[16712], 95.00th=[16712],
| 99.00th=[16712], 99.50th=[16712], 99.90th=[16712], 99.95th=[16712],
| 99.99th=[16712]
bw (KB /s): min= 0, max= 17, per=9.55%, avg= 1.82, stdev= 3.77
write: io=983040B, bw=4945B/s, iops=0, runt=198759msec
clat (msec): min=52, max=120330, avg=49218.75, stdev=35050.84
lat (msec): min=52, max=120330, avg=49218.75, stdev=35050.84
clat percentiles (msec):
| 1.00th=[ 53], 5.00th=[ 3621], 10.00th=[ 3654], 20.00th=[10683],
| 30.00th=[16712], 40.00th=[16712], 50.00th=[16712], 60.00th=[16712],
| 70.00th=[16712], 80.00th=[16712], 90.00th=[16712], 95.00th=[16712],
| 99.00th=[16712], 99.50th=[16712], 99.90th=[16712], 99.95th=[16712],
| 99.99th=[16712]
bw (KB /s): min= 0, max= 4, per=17.50%, avg= 0.70, stdev= 1.44
lat (msec) : 2=0.33%, 4=0.33%, 10=1.64%, 20=2.30%, 50=64.80%
lat (msec) : 100=0.33%, >=2000=30.26%
cpu : usr=0.00%, sys=0.00%, ctx=315, majf=0, minf=0
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=244/w=60/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=3904KB, aggrb=19KB/s, minb=19KB/s, maxb=19KB/s, mint=198759msec, maxt=198759msec
WRITE: io=960KB, aggrb=4KB/s, minb=4KB/s, maxb=4KB/s, mint=198759msec, maxt=198759msec
Disk stats (read/write):
sdb: ios=240/59, merge=0/0, ticks=1425452/2832236, in_queue=4893344, util=100.00%