Fio 使用小结

来源:互联网 发布:网络播放器批发 编辑:程序博客网 时间:2024/06/06 08:52
Fio 使用小结
Performance test 2011-03-10 23:37:19 阅读54 评论0   字号:大中小 订阅
fio是一个基于GPLV2授权的开源压力测试工具,主要是用来测试磁盘io性能,也有cpu,nic的io测试功能。


支持平台:Linux, FreeBSD, NetBSD, OS X, OpenSolaris, AIX, Windows


安装依赖包:libaio-devel
 
下载地址: http://freshmeat.net/projects/fio/


这个工具的可定制性非常强,可以根据测试者的想法进行各种混合io的测试


安装方法:详见readme


随机读写


fio模拟iometer
配置文件方式:
#cat iometer-file-access-server
[global]


bssplit=512/20:1k/20:2k/10:4k/40:8k/10
 
#2成512B,1KB,1成2KB,4成4KB,1成8KB的小文件进行测试
rw=randrw
rwmixread=80 #8成读,2成写
direct=1 #不使用io设备buffer
size=4g
numjobs=16 #产生16个进程
nrfiles=8 #每1个进程生成文件数量
ioengine=libaio
 
#IO engine,种类丰富,测试nfs,cpu,nic使用不同的引擎。
directory=/mnt
# IOMeter defines the server loads as the following:
# iodepth=1 Linear
# iodepth=4 Very Light
# iodepth=8 Light
# iodepth=64 Moderate
# iodepth=256 Heavy


iodepth=64 #每个文件io队列长度
lockmem=1g #fio只使用1g内存进行测试
zero_buffers 用0初始化系统buffer


一般fio配置文件和参数都是支持k/m/g的标识


顺序测试
命令行方式
fio –name=iometer --rw=randrw --size=4096m --bssplit=32K/20:64k/40:256k/20:512k/20 --direct=1 --ioengine=libaio --iodepth=32 -directory=/mnt --numjobs=8 --nrfiles=8 --rwmixread=60 --zero_buffers




模拟tiobench


# cat tiobench-example


[global]
direct=1
ioengine=libaio
size=512m
bsrange=4k-64k
timeout=60
numjobs=4


[f1]
rw=write
ioengine=sync
bsrange=4k-4k
timeout=120
numjobs=8


[f2]
stonewall
#等待上一个任务完成再开始
rw=randwrite


[f3]
stonewall
ioengine=posixaio
rw=read


[f4]
stonewall
rw=randread


其他参数详见help或者man page。
每一个子选项可以根据自己的需要再次配置,这个可以使用fio来模拟多种混合io。


测试CPU IO
# cat fiocpu.cfg
[global]
readwrite=randrw
name=stresser
directory=/tmp
size=8G
bssplit=32K/20:64k/40:256k/20:512k/20
nrfiles=16
fsync_on_close=1
thread


[cpu0]
ioengine=cpuio
cpuload=100
runtime=300
[cpu1]
ioengine=cpuio
cpuload=100
runtime=300


测试nic IO
测试网络
# cat fionet
[global]
ioengine=net
#the below defaults to a tcp connection, add /udp at the end for udp
filename=localhost/8888
bs=4k
size=10g
iodepth=128
#verify=sha512
#支持md5 crc16 crc32 crc64 crc7 sha256 sha512


[receiver]
rw=read


[sender]
rw=write


[receiver]

rw=read


[sender]

rw=write


example output:
$ fio --name=global --rw=randrw --size=128m --name=job1 --name=job2
job1: (g=0): rw=randrw, bs=4K-4K/4K-4K, ioengine=sync, iodepth=1
job2: (g=0): rw=randrw, bs=4K-4K/4K-4K, ioengine=sync, iodepth=1
Starting 2 processes
Jobs: 1 (f=1): [_m] [99.6% done] [516K/565K /s] [126/138 iops] [eta 00m:01s]
job1: (groupid=0, jobs=1): err= 0: pid=5117
read : io=65880KB, bw=298486B/s, iops=72, runt=226011msec
clat (usec): min=119, max=977960, avg=13487.89, stdev=37647.61
bw (KB/s) : min= 4, max= 603, per=51.98%, avg=300.42, stdev=113.69
write: io=65192KB, bw=295368B/s, iops=72, runt=226011msec
clat (usec): min=10, max=196312, avg=219.16, stdev=4909.93
bw (KB/s) : min= 4, max= 736, per=51.64%, avg=295.87, stdev=132.08
cpu : usr=0.05%, sys=0.57%, ctx=16529, majf=0, minf=555
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 r/w: total=16470/16298, short=0/0
lat (usec): 20=44.48%, 50=4.92%, 100=0.21%, 250=0.79%, 500=0.07%
lat (usec): 750=0.01%
lat (msec): 2=0.58%, 4=10.53%, 10=33.08%, 20=2.33%, 50=0.56%
lat (msec): 100=0.29%, 250=1.96%, 500=0.18%, 750=0.01%, 1000=0.01%
job2: (groupid=0, jobs=1): err= 0: pid=5118
read : io=65716KB, bw=295669B/s, iops=72, runt=227596msec
clat (usec): min=118, max=974169, avg=13608.29, stdev=38346.81
bw (KB/s) : min= 19, max= 766, per=51.65%, avg=298.54, stdev=122.36
write: io=65356KB, bw=294049B/s, iops=71, runt=227596msec
clat (usec): min=9, max=171343, avg=229.40, stdev=5166.00
bw (KB/s) : min= 5, max= 763, per=51.24%, avg=293.60, stdev=138.74
cpu : usr=0.07%, sys=0.54%, ctx=16489, majf=0, minf=1324
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 r/w: total=16429/16339, short=0/0
lat (usec): 10=0.01%, 20=44.36%, 50=5.16%, 100=0.19%, 250=0.91%
lat (usec): 500=0.05%, 750=0.02%, 1000=0.01%
lat (msec): 2=0.64%, 4=10.23%, 10=33.26%, 20=2.38%, 50=0.41%
lat (msec): 100=0.17%, 250=2.01%, 500=0.20%, 750=0.01%, 1000=0.02%


Run status group 0 (all jobs):
READ: io=131596KB, aggrb=578KB/s, minb=295KB/s, maxb=298KB/s, mint=226011msec, maxt=227596msec
WRITE: io=130548KB, aggrb=573KB/s, minb=294KB/s, maxb=295KB/s, mint=226011msec, maxt=227596msec


Disk stats (read/write):

sdb: ios=32878/8303, merge=0/1095, ticks=445868/20400284, in_queue=20964472, util=99.98%


------------------------------------

结果说明:

iops: IOs perform persecond

clat: complete latency

stdev: standard deviation

iodepth: subit work depth


aggrb: aggregate bandwidth

minb, maxb: minum and maxium bandwidth per thread saw

mint, maxt: min and max runtime per thread

ios: number of IOs perform

merge: # of merge in IO

ticks: # of ticks keep disk busy

in_queue:Total time spend in disk queue

util: utilization percent


io系统的压力测试工具-fio

 

fio是一个非常灵活的io测试工具,他可以通过多线程或进程模拟各种io操作

随着块设备的发展,特别是SSD盘的出现,设备的并行度越来越高。要想利用好这些设备,有个诀窍就是提高设备的iodepth, 一次喂给设备更多的IO请求,让电梯算法和设备有机会来安排合并以及内部并行处理,提高总体效率。

应用程序使用IO通常有二种方式:同步和异步。 同步的IO一次只能发出一个IO请求,等待内核完成才返回,这样对于单个线程iodepth总是小于1,但是可以通过多个线程并发执行来解决,通常我们会用16-32个线程同时工作把iodepth塞满。 异步的话就是用类似libaio这样的linux native aio一次提交一批,然后等待一批的完成,减少交互的次数,会更有效率。

io队列深度通常对不同的设备很敏感,那么如何用fio来探测出合理的值呢?在fio的帮助文档里是如何解释iodepth相关参数的

iodepth=int
iodepth_batch=int
iodepth_batch_complete=int
iodepth_low=int
fsync=int
direct=bool

这几个参数在libaio的引擎下的作用,会用iodepth值来调用io_setup准备一个可以一次提交iodepth个IO的上下文,同时申请一个io请求队列用于保持IO。 在压测进行的时候,系统会生成特定的IO请求,往io请求队列里面扔,当队列里面的IO数量达到iodepth_batch值的时候,就调用io_submit批次提交请求,然后开始调用io_getevents开始收割已经完成的IO。 每次收割多少呢?由于收割的时候,超时时间设置为0,所以有多少已完成就算多少,最多可以收割iodepth_batch_complete值个。随着收割,IO队列里面的IO数就少了,那么需要补充新的IO。 什么时候补充呢?当IO数目降到iodepth_low值的时候,就重新填充,保证OS可以看到至少iodepth_low数目的io在电梯口排队着。

 

下载
[root@vmforDB05 tmp]# wget ftp://ftp.univie.ac.at/systems/linux/dag/redhat/el5/en/x86_64/dag/RPMS/fio-2.0.6-1.el5.rf.x86_64.rpm

安装
[root@vmforDB05 tmp]# rpm -ivh fio-2.0.6-1.el5.rf.x86_64.rpm

 

测试下
[root@vmforDB05 ~]# fio -filename=/dev/mapper/cachedev  -direct=1 -rw=randread -bs=8k -size 1G -numjobs=8 -runtime=30 -group_reporting -name=file
file: (g=0): rw=randread, bs=8K-8K/8K-8K, ioengine=sync, iodepth=1
...
file: (g=0): rw=randread, bs=8K-8K/8K-8K, ioengine=sync, iodepth=1
fio 2.0.6
Starting 8 processes
Jobs: 1 (f=1): [____r___] [13.2% done] [200K/0K /s] [24 /0  iops] [eta 03m:30s]
file: (groupid=0, jobs=8): err= 0: pid=22052
  read : io=4632.0KB, bw=156907 B/s, iops=19 , runt= 30229msec
    clat (usec): min=168 , max=1585.8K, avg=409213.69, stdev=234820.76
     lat (usec): min=169 , max=1585.8K, avg=409214.35, stdev=234820.77
    clat percentiles (msec):
     |  1.00th=[   28],  5.00th=[   61], 10.00th=[  114], 20.00th=[  200],
     | 30.00th=[  273], 40.00th=[  334], 50.00th=[  392], 60.00th=[  445],
     | 70.00th=[  510], 80.00th=[  578], 90.00th=[  717], 95.00th=[  816],
     | 99.00th=[ 1057], 99.50th=[ 1221], 99.90th=[ 1582], 99.95th=[ 1582],
     | 99.99th=[ 1582]
    bw (KB/s)  : min=    4, max=  202, per=12.72%, avg=19.46, stdev=13.99
    lat (usec) : 250=0.17%
    lat (msec) : 50=4.15%, 100=4.84%, 250=16.58%, 500=42.14%, 750=24.18%
    lat (msec) : 1000=6.56%, 2000=1.38%
  cpu          : usr=0.03%, sys=0.09%, ctx=1102, majf=0, minf=244
  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=579/w=0/d=0, short=r=0/w=0/d=0

Run status group 0 (all jobs):
   READ: io=4632KB, aggrb=153KB/s, minb=156KB/s, maxb=156KB/s, mint=30229msec, maxt=30229msec

Disk stats (read/write):
    dm-0: ios=578/0, merge=0/0, ticks=169684/0, in_queue=169733, util=98.95%, aggrios=0/0, aggrmerge=0/0, aggrticks=0/0, aggrin_queue=0, aggrutil=0.00%
  loop0: ios=0/0, merge=0/0, ticks=0/0, in_queue=0, util=0.00%
  loop1: ios=0/0, merge=0/0, ticks=0/0, in_queue=0, util=0.00%
[root@vmforDB05 ~]#

 


fio可以通过配置文件来配置压力测试的方式,可以用选项 --debug=io来检测fio是否工作

[root@vmforDB05 tmp]# cat fio_test 
[global]  
bsrange=512-2048  
ioengine=libaio  
userspace_reap  
rw=randrw  
rwmixwrite=20  
time_based  
runtime=180  
direct=1  
group_reporting  
randrepeat=0  
norandommap  
ramp_time=6  
iodepth=16  
iodepth_batch=8  
iodepth_low=8  
iodepth_batch_complete=8  
exitall  
[test]  
filename=/dev/mapper/cachedev  
numjobs=1 

常用参数说明
bsrange=512-2048  //数据块的大小范围,从512bytes到2048 bytes 
ioengine=libaio        //指定io引擎
userspace_reap      //配合libaio,提高异步io的收割速度
rw=randrw                //混合随机对写io,默认读写比例5:5
rwmixwrite=20         //在混合读写的模式下,写占20%
time_based             //在runtime压力测试周期内,如果规定数据量测试完,要重复测试 
runtime=180            //在180秒,压力测试将终止
direct=1                    //设置非缓冲io
group_reporting      //如果设置了多任务参数numjobs,用每组报告代替每job报告
randrepeat=0         //设置产生的随机数是不可重复的
norandommap  
ramp_time=6  
iodepth=16  
iodepth_batch=8  
iodepth_low=8  
iodepth_batch_complete=8  
exitall                                                     //一个job完成,就停止所有的
filename=/dev/mapper/cachedev    //压力测试的文件名
numjobs=1                                         //job的默认数量,也就是并发数,默认是1
size=200G                                          //这job总共的io大小
refill_buffers                                      //每次提交后都重复填充io buffer
overwrite=1                                       //设置文件可覆盖
sync=1                                              //设置异步io
fsync=1                                             //一个io就同步数据
invalidate=1                                   //开始io之前就失效buffer-cache
directory=/your_dir                        // fielname参数值的前缀
thinktime=600                              //在发布io前等待600秒
thinktime_spin=200    //消费cpu的时间,thinktime的剩余时间sleep
thinktime_blocks=2    //在thinktime之前发布的block数量

bssplit=4k/30:8k/40:16k/30            //随机读4k文件占30%、8k占40%、16k占30%
rwmixread=70