Introduction
FIO is a tool for testing IOPS. It is used to stress test and verify disks. Disk I/O is an important indicator for checking disk performance. It can be divided into two categories: sequential read and write and random read and write according to load conditions. FIO can Generate many threads or processes and execute specific types of I/O operations specified by the user. The typical use is to write job files that match the simulated I/O load. That is to say, FIO is a multi-threaded I/O generation tool that can generate multiple An I/O mode used to test the performance of disk devices.
Install
wget https://git.kernel.dk/cgit/fio/snapshot/fio-3.32.tar.gz
tar -xvf fio-3.32.tar.gz
cd fio-3.32
./configure --prefix=/opt/software/fio3.32
make -j 16
make install
–prefix: installation path.
Create a soft link:
ln -s /opt/software/fio3.32 /usr/bin/fio
test installation
fio -v
engine libaio not loadable
You need to install libaio, note that there is a 1 in the first line.
apt-get install libaio1
apt-get install libaio-dev
Then recompile and install.
cd fio-3.32
./configure --prefix=/opt/software/fio3.32
make -j 16
make install
Check whether libaio is installed successfully.
fio --enghelp | grep libaio
Introduction to Common Parameters
-filename=/dev/sdb #要测试盘的名称,支持文件系统或者裸设备,/dev/sda2或/dev/sdb
-direct=1 #测试过程绕过机器自带的buffer,使测试结果更真实(Linux在读写时,数据会先写到缓存,再在后台写到硬盘,读的时候也是优先从缓存中读,这样访问速度会加快,但是一旦掉电,缓存中数据就会清空,所有一种模式为DirectIO,可以跳过缓存,直接读写硬盘)
-ioengine=libaio #定义使用什么io引擎去下发io请求,常用的一些 libaio:Linux本地异步I/O;rbd:通过librbd直接访问CEPH Rados
-iodepth=16 #队列的深度为16,在异步模式下,CPU不能一直无限的发命令到硬盘设备。比如SSD执行读写如果发生了卡顿,那有可能系统会一直不停的发命令,几千个,甚至几万个,这样一方面SSD扛不住,另一方面这么多命令会很占内存,系统也要挂掉了。这样,就带来一个参数叫做队列深度。
-bs=4k #单次io的块文件大小为4k
-numjobs=10 #本次测试的线程数是10
-size=5G #每个线程读写的数据量是5GB
-runtime=60 #测试时间为60秒,可以设置2m为两分钟。如果不配置此项,会将设置的size大小全部写入或者读取完为止
-rw=randread #测试随机读的I/O
-rw=randwrite #测试随机写的I/O
-rw=randrw #测试随机混合写和读的I/O
-rw=read #测试顺序读的I/O
-rw=write #测试顺序写的I/O
-rw=rw #测试顺序混合写和读的I/O
-thread #使用pthread_create创建线程,另一种是fork创建进程。进程的开销比线程要大,一般都采用thread测试
rwmixwrite=30 #在混合读写的模式下,写占30%(即rwmixread读为70%,单独配置这样的一个参数即可)
-group_reporting #关于显示结果的,汇总每个进程的信息
-name="TDSQL_4KB_read_test" #定义测试任务名称
扩展
-lockmem=1g #只使用1g内存进行测试
-zero_buffers #用全0初始化缓冲区,默认是用随机数据填充缓冲区
-random_distribution=random #默认情况下,fio 会在询问时使用完全均匀的随机分布,有需要的话可以自定义访问区域,zipf、pareto、normal、zoned
-nrfiles=8 #每个进程生成文件的数量
test example
100% random read, 5G size, 4k block file:
fio -filename=/dev/sdb -direct=1 -ioengine=libaio -bs=4k -size=5G -numjobs=10 -iodepth=16 -runtime=60 -thread -rw=randread -group_reporting -name="TDSQL_4KB_randread_test"
100% sequential read, 5G size, 4k block file:
fio -filename=/dev/sdb -direct=1 -ioengine=libaio -bs=4k -size=5G -numjobs=10 -iodepth=16 -runtime=60 -thread -rw=read -group_reporting -name="TDSQL_4KB_write_test"
70% random read, 30% random write, 5G size, 4k block file:
fio -filename=/dev/sdb -direct=1 -ioengine=libaio -bs=4k -size=5G -numjobs=10 -iodepth=16 -runtime=60 -thread -rw=randrw -rwmixread=70 -group_reporting -name="TDSQL_4KB_randread70-write_test"
70% sequential read, 30% sequential write, 5G size, 4k block file:
fio -filename=/dev/sdb -direct=1 -ioengine=libaio -bs=4k -size=5G -numjobs=10 -iodepth=16 -runtime=60 -thread -rw=rw -rwmixread=70 -group_reporting -name="TDSQL_4KB_read70-write_test"
run via configuration file
test.fio:
[global]
filename=/dev/sdb
ioengine=libaio
direct=1
thread
group_reporting
[randread-4k-128M]
rw=randread
bs=4k
size=128M
numjobs=5
[randwrite-4k-128M]
rw=randwrite
bs=4k
size=128M
numjobs=5
[write-4k-128M]
rw=write
bs=4k
size=128M
numjobs=5
fio test.fio