顺序读写 (吞吐量bw,常用单位为MB/s):文件在硬盘上存储位置是连续的。
适用场景:大文件拷贝(比如视频音乐)。
4K随机读写 (IOPS,常用单位为次):在硬盘上随机位置读写数据,每次4KB。
适用场景:操作系统运行、软件运行、数据库。
测试硬盘性能时,建议直接测试裸数据盘(如 /dev/vdb)。
测试文件系统性能时,推荐指定具体文件测试(如 /data/file)。
数据盘的大小要大于指定size的大小,否则会报错.
1.查看是否已经安装FIO
fio
-bash: fio: command not found //未安装
fio-2.2.5 //已经安装
2.如果没有安装,则需要安装FIO.
wget http://brick.kernel.dk/snaps/fio-2.2.5.tar.gz
yum install libaio-devel
tar -zxvf fio-2.2.5.tar.gz
cd fio-2.2.5
make
make install
1.fdisk -l 查看你的磁盘名称型号,一般磁盘都是在/dev下,叫sdb,或者vdb
/dev/vda 是系统盘,有21.5G
有一个系统盘分区是vda1,/dev/vda1 约20G
有一个数据盘 /dev/vdb 42.9G
2.测试裸盘不需要分区,不需要格式化,不需要挂载,直接利用fio,配合测试脚本进行测试即可.
测试文件系统,一定要注意,测试文件系统容易导致文件系统损坏.所以我们采用dd命令创建一个大文件,读写这个大文件.测试方式和测试裸盘一样.只是filename为这个文件的路径.
首先要分区,格式化,挂载.
如何用dd创建大文件,查看我上一篇文章.
查看硬盘信息:fdisk -l
[root@i-5jauz4g8hoduu9wv8tpuz5ns3 ~]# fdisk -l
Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 41943039 20970496 83 Linux
Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
磁盘分区
[root@i-5jauz4g8hoduu9wv8tpuz5ns3 ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x57a611b9.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-83886079, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079):
Using default value 83886079
Partition 1 of type Linux and of size 40 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@i-5jauz4g8hoduu9wv8tpuz5ns3 ~]# fdisk -l
Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 41943039 20970496 83 Linux
Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x57a611b9
Device Boot Start End Blocks Id System
/dev/vdb1 2048 83886079 41942016 83 Linux
磁盘格式化,ext3和ext4没什么很大区别
[root@i-5jauz4g8hoduu9wv8tpuz5ns3 ~]# mkfs.ext3 /dev/vdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10485504 blocks
524275 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
320 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
磁盘挂载,这里要注意:
1.挂载的目录
2. mount /dev/vdb1 /dev/data1 vdb1 /dev之间是有个空格的,如果不加空格会报错
挂载完毕之后,df -h查看一下挂载情况,发现已经挂载上了
[root@i-5jauz4g8hoduu9wv8tpuz5ns3 dev]# mkdir data1
[root@i-5jauz4g8hoduu9wv8tpuz5ns3 dev]# ls
data1 vda vdb vda1 vdb1
[root@i-5jauz4g8hoduu9wv8tpuz5ns3 dev]# mount /dev/vdb1 /data1
mount: mount point /data1 does not exist
[root@i-5jauz4g8hoduu9wv8tpuz5ns3 dev]# mount /dev/vdb1 /dev/data1
[root@i-5jauz4g8hoduu9wv8tpuz5ns3 dev]# cd data1
[root@i-5jauz4g8hoduu9wv8tpuz5ns3 data1]# ls
lost+found
[root@i-5jauz4g8hoduu9wv8tpuz5ns3 data1]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 1.5G 18G 9% /
devtmpfs 911M 0 911M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 340K 920M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
tmpfs 184M 0 184M 0% /run/user/0
/dev/vdb1 40G 49M 38G 1% /dev/data1
重启自动挂载
编辑/etc/fstab文件,再最后面添加
/dev/sdc1(磁盘分区) /disk/disktwo(挂载目录) ext3(文件格式)defaults 0 0
vim /etc/fstab
/dev/sdc1(磁盘分区) /disk/disktwo(挂载目录) ext3(文件格式)defaults 0 0
read300k-rand:
主要关注iops,alt(average),bw这三个参数
iops=19776,(英文:Input/Output Operations Per Second),即每秒进行读写(I/O)操作的次数
bw=5794.2MB/s 带宽,磁盘的吞吐量,io/runt,每秒的传输速率
lat avg=6467.95 从IO结构体创建时刻开始,直到紧接着clat完成的时间
[root@i-5ja3ouj5zpd5phkajbmv6wqzn ~]# fio --name=read300k-rand --ioengine=libaio --direct=1 --thread=1 --norandommap=1
--randrepeat=0 --runtime=100 --ramp_time=6 --size=16g --filename=/dev/vdb1 --log_avg_msec=500 --stonewall --group_repor ting --time_based --bs=300k --rw=randread --numjobs=1 --iodepth=128 --write_bw_log=fio-test-read300k-rand --write_iops_ log=fio-test-read300k-rand --write_lat_log=fio-test-read300k-rand
read300k-rand: (g=0): rw=randread, bs=300K-300K/300K-300K/300K-300K, ioengine=libaio, iodepth=128
fio-2.2.5
Starting 1 thread
Jobs: 1 (f=1): [r(1)] [100.0% done] [6676MB/0KB/0KB /s] [22.8K/0/0 iops] [eta 00m:00s]
read300k-rand: (groupid=0, jobs=1): err= 0: pid=14623: Thu Sep 19 10:14:36 2019
read : io=579340MB, bw=5794.2MB/s, iops=19776, runt= 99987msec
slat (usec): min=10, max=904, avg=27.04, stdev=17.24
clat (usec): min=49, max=23443, avg=6440.70, stdev=3461.08
lat (usec): min=74, max=23468, avg=6467.95, stdev=3460.05
clat percentiles (usec):
| 1.00th=[ 2448], 5.00th=[ 2992], 10.00th=[ 3312], 20.00th=[ 3568],
| 30.00th=[ 3728], 40.00th=[ 3984], 50.00th=[ 5088], 60.00th=[ 6496],
| 70.00th=[ 7904], 80.00th=[ 9664], 90.00th=[11712], 95.00th=[13248],
| 99.00th=[15936], 99.50th=[16768], 99.90th=[18048], 99.95th=[18560],
| 99.99th=[19840]
bw (MB /s): min= 0, max= 7114, per=99.41%, avg=5759.87, stdev=776.55
lat (usec) : 50=0.01%, 100=0.01%, 250=0.01%, 500=0.01%, 750=0.01%
lat (usec) : 1000=0.01%
lat (msec) : 2=0.11%, 4=40.19%, 10=41.26%, 20=18.42%, 50=0.01%
cpu : usr=3.05%, sys=64.40%, ctx=11901, majf=0, minf=418
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=0.1%, >=64=106.5%
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.1%
issued : total=r=1977354/w=0/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=128
Run status group 0 (all jobs):
READ: io=579340MB, aggrb=5794.2MB/s, minb=5794.2MB/s, maxb=5794.2MB/s, mint=99987msec, maxt=99987msec
Disk stats (read/write):
vdb: ios=2107144/38, merge=0/0, ticks=8106727/0, in_queue=8106977, util=96.49%