一直都使用fio ,不过也没时间记录,趁着周末整理一下,当做记录留着备用。
FIO是测试IOPS的非常好的工具,用来对硬件进行压力测试和验证,它支持16 种不同的I/O引擎,
包括: binject sg splice e4defrag falloc posixaio libaio net netsplice null sync psync vsync pvsync mmap cpuio。
具体可参加 fio 官网地址:http://freshmeat.net/projects/fio/
本次使用的是fio-2.1.7版本,也算是最新版。
一,安装FIO
安装非常的简单wget http://brick.kernel.dk/snaps/fio-2.1.7.tar.gz
yum install libaio-devel
tar -zxvf fio-2.1.7.tar.gz
cd fio-2.1.7
make
make install
二,查看命令帮助
1,普通帮助文档
2,查看fio支持的读写模式
3,查看所有参数的详细信息
三,执行测试
一般可以将所有测试情况写入到一个脚本,方便测试,这里给出一个简单的脚本例子:
FIO_CMD="/usr/local/bin/fio" ###fio命令路径
FILE_NAME="/dev/sdc1" ####要测试的分区
RW_MODE="read randread write randwrite randrw" ####要测试的读写模式
RUN_TIME=900 ####SECONDS#####
NUM_THREADS=16 ###并发数
FILE_SIZE="80G" ####测试文件大小
RW_RATION=90 ####读写比
IO_MODE="libaio psync sync" ## io引擎
BLOCK_SIZE="4K" ###测试的块大小
SLEEP_TIME=120 #####SECONDS###
DRY_RUN="" #"--parse-only"
DATE_TIME=`date +'%Y%m%d-%H%M%S'`
for bs in ${BLOCK_SIZE}
do
for rw_mode in ${RW_MODE}
do
for io_mode in ${IO_MODE}
do
echo "###############rw_mode: ${rw_mode} io_mode: ${io_mode} === block_size: ${bs}#################"
${FIO_CMD} -filename=${FILE_NAME} -direct=1 -iodepth 1 -thread -rw=${rw_mode} -rwmixread=${RW_RATION} \
-ioengine=${io_mode} -bs=${bs} -size=${FILE_SIZE} -numjobs=${NUM_THREADS} -runtime=${RUN_TIME} \
-group_reporting -name=mytest ${DRY_RUN}
sleep ${SLEEP_TIME}
done;
done;
done;
另外给出测试结果如下:
###############rw_mode: read io_mode: libaio === block_size: 4K######################
mytest: (g=0): rw=read, bs=4K-4K/4K-4K/4K-4K, ioengine=libaio, iodepth=1
...
fio-2.1.7
Starting 16 threads
mytest: (groupid=0, jobs=16): err= 0: pid=10484: Fri May 16 12:21:01 2014
read : io=303700MB, bw=345542KB/s, iops=86385, runt=900001msec
slat (usec): min=2, max=13192, avg=31.68, stdev=44.39
clat (usec): min=0, max=18631, avg=149.86, stdev=168.29
lat (usec): min=35, max=18852, avg=182.08, stdev=171.16
clat percentiles (usec):
| 1.00th=[ 2], 5.00th=[ 59], 10.00th=[ 77], 20.00th=[ 96],
| 30.00th=[ 109], 40.00th=[ 122], 50.00th=[ 135], 60.00th=[ 151],
| 70.00th=[ 169], 80.00th=[ 193], 90.00th=[ 235], 95.00th=[ 278],
| 99.00th=[ 406], 99.50th=[ 490], 99.90th=[ 780], 99.95th=[ 988],
| 99.99th=[ 3536]
bw (KB /s): min=13912, max=38648, per=6.25%, avg=21601.35, stdev=1511.85
lat (usec) : 2=0.40%, 4=0.95%, 10=0.16%, 20=0.20%, 50=1.76%
lat (usec) : 100=19.10%, 250=69.59%, 500=7.36%, 750=0.35%, 1000=0.07%
lat (msec) : 2=0.03%, 4=0.01%, 10=0.01%, 20=0.01%
cpu : usr=2.95%, sys=23.60%, ctx=77085017, majf=0, minf=44
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=77747121/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=303700MB, aggrb=345542KB/s, minb=345542KB/s, maxb=345542KB/s, mint=900001msec, maxt=900001msec
Disk stats (read/write):
sdc: ios=76615853/0, merge=1102787/0, ticks=11140723/0, in_queue=10907632, util=100.00%
这里测试出的硬盘iops大概是8w左右,看来还是不错的
(友情提示:fio写测试是侵入式的,如果需要测试某个分区,请先备份,否则所有数据将会被清除)
测试写入后 执行df -h 你可能会看到如下情况:
解决办法:
umount /database2
mkfs.ext4 /dev/sdc1
mount -t ext4 -o rw -o noatime -o nodiratime -o barrier=0 /dev/sdc1 /database2
如此即可继续测试
下图是我在对两块intel dc s3500 raid 1硬盘的测试结果图,仅供参考:
最后附上常用参数说明:
常用参数说明参考了部分网上内容:
bsrange=512-2048 //数据块的大小范围,从512bytes到2048bytes
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 // io深度
iodepth_batch=8 // 批量处理io的多少
iodepth_low=8 // 最低io水位线
iodepth_batch_complete=8 // 每次批量处理的io数量
exitall //一个job完成,就停止所有的
filename=/dev/mapper/cachedev //压力测试的文件名
numjobs=1 //job的默认数量,也就是并发数,默认是1
size=80G //这job总共的io大小
refill_buffers //每次提交后都重复填充iobuffer
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 //读占70%