找回密码
 立即注册
搜索
热搜: SDN 云计算 H3C
查看: 1803|回复: 0

[CentOS] [荐]centos 磁盘IO读写性能测试工具

[复制链接]

41

主题

1

精华

0

回帖

实习版主

体力
186 卡
贡献
42 个
金币
128 枚
注册时间
2020-1-23
最后登录
2025-3-21

活跃会员热心会员推广达人宣传达人灌水之王突出贡献优秀版主荣誉管理论坛元老最佳新人

发表于 2023-1-12 23:04:35 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 lovet 于 2023-1-12 23:06 编辑

1. time+dd
mkdir -p /root/test

写:time dd if=/dev/md126 of=/root/test/out bs=8k
读:time dd if=/root/test/out of=/dev/null bs=8k

写速度
$dd if=/dev/zero bs=1k count=1000000 of=1Gb.file
1000000+0 records in
1000000+0 records out
1024000000 bytes (1.0 GB) copied, 5.13676 seconds, 199 MB/s

读速度
$dd if=1Gb.file bs=64k |dd of=/dev/null
[haibo@localhost ~]$ dd if=1Gb.file bs=64k |dd of=/dev/null
15625+0 records in
15625+0 records out
1024000000 bytes (1.0 GB) copied, 6.37813 seconds, 161 MB/s
2000000+0 records in
2000000+0 records out
1024000000 bytes (1.0 GB) copied, 6.37891 seconds, 161 MB/s

读写速度
$dd if=1Gb.file of=2Gb.file bs=64k
15625+0 records in
15625+0 records out
1024000000 bytes (1.0 GB) copied, 2.21364 seconds, 463 MB/

写速度:
time dd if=/dev/zero of=test.dbf bs=8k count=300000
其中/dev/zero是一个伪设备,它只产生空字符流,对它不会产生IO,所以,IO都会集中在of文件中,of文件只用于写,所以这个命令相当于测试磁盘的写能力。
输出的结果类似(因为一般更长测试时间更准确,所以可以设置count大一些):

读速度:
time dd if=/dev/sda1 of=/dev/null bs=8k count=300000
因为/dev/sdb1是一个物理分区,对它的读取会产生IO,/dev/null是伪设备,相当于黑洞,of到该设备不会产生IO,所以,这个命令的IO只发生在/dev/sdb1上,也相当于测试磁盘的读能力  

Linux time命令、dd命令、测试硬盘读写速度、磁盘备份恢复​
time命令常用于测量一个命令的运行时间,注意不是用来显示和修改系统时间的(这是date命令干的事情)。它不仅仅是测量运行时间,还可以测量内存、I/O等的使用情况。一个程序在运行时使用的系统资源通常包括CPU、Memory和I/O等,其中CPU资源的统计包括实际使用时间(real time)、用户态使用时间(the process spent in user mode)、内核态使用时间(the process spent in kernel mode)。但是简单的使用time命令并不能得到内存和I/O的统计数据

命令格式:
time <command> [<arguments...>]

例子:time find . -name "mysql.sh"
在命令执行完成之后就会打印出CPU的使用情况:
real    0m14.837s <== 实际使用时间(real time)
user    0m0.030s  <== 用户态使用时间(the process spent in user mode)
sys     0m0.120s  <== 内核态使用时间(the process spent in kernel mode)
注1:real远大于user加上sys,因为find需要遍历各个目录,需要大量的I/O操作,而磁盘I/O通常是最慢的环节,因此大部分时间find进程都在等待磁盘I/O完成。
注2:使用-p参数时,就直接打印所需时间的数值,单位为秒,而不是更友好的格式,包括分钟、秒钟的显示方式。

Linux系统中time命令其实不止一个:
执行type -a time命令
time is a shell keyword
time is /usr/bin/time
通过这条命令我们可以发现我们常用的time其实是一个Shell关键字,还有一个外部命令/usr/bin/time(外部命令功能更强大)
例子:使用外部time命令输出内存、IO等更加多的信息 /usr/bin/time -v find . -name "mysql.sh"
time命令输出信息的重定向:time命令的输出信息是打印在标准错误输出上的

方法1: 将time命令和将要执行的命令行放到一个shell代码块中,也就是一对大括号。如下,注意分隔符、空格的使用。
{ time command-line; } 2>file

方法2: 使用子Shell的方式。如下,这里time紧贴着小括号(也可以的,命令行结束也不必带分号。当然最好还是用第一种方式,毕竟启动一个子shell是要多占些资源的。
(time command-line) 2>file

dd命令:Linux/UNIX 下的一个非常有用的命令,作用是用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换。
dd 的主要选项:
if=file: 输入文件名,缺省为标准输入。
of=file: 输出文件名,缺省为标准输出。
count=blocks: 仅拷贝 blocks 个块,块大小等于 ibs 指定的字节数。
bs=bytes: 同时设置读写块的大小为 bytes ,可代替 ibs 和 obs 。
ibs=bytes: 一次读入 bytes 个字节(即一个块大小为 bytes 个字节)。
obs=bytes: 一次写 bytes 个字节(即一个块大小为 bytes 个字节)。
cbs=bytes: 一次转换 bytes 个字节,即转换缓冲区大小。
skip=blocks: 从输入文件开头跳过 blocks 个块后再开始复制。
seek=blocks: 从输出文件开头跳过 blocks 个块后再开始复制。(通常只有当输出文件是磁盘或磁带时才有效)。
conv=conversion[,conversion...]: 用指定的参数转换文件。
conv = ASCII 把EBCDIC码转换为ASCII码。
conv = ebcdic 把ASCII码转换为EBCDIC码。
conv = ibm 把ASCII码转换为alternate EBCDIC码。
conv = blick 把变动位转换成固定字符。
conv = ublock 把固定们转换成变动位
conv = ucase 把字母由小写变为大写。
conv = lcase 把字母由大写变为小写。
conv = notrunc 不截短输出文件。
conv = swab 交换每一对输入字节。
conv = noerror 出错时不停止处理。
conv = sync 把每个输入记录的大小都调到ibs的大小(用ibs填充)。
​结合time、dd命令测试硬盘读写速度:

/dev/null:是一个伪设备,相当于回收站,of到该设备不会产生IO
/dev/zero:是一个伪设备,它只产生空字符流,对它不会产生IO
测试磁盘写能力:time dd if=/dev/zero of=test.dbf bs=8k count=300000
测试磁盘读能力:time dd if=/dev/sda1 of=/dev/null bs=8k
测试同时读写能力:time dd if=/dev/sda1 of=test1.dbf bs=8k

磁盘备份恢复:
将本地的/dev/hdx整盘备份到/dev/hdy :dd if=/dev/hdx of=/dev/hdy
将/dev/hdx全盘数据备份到指定路径的image文件:dd if=/dev/hdx of=/path/to/image
备份/dev/hdx全盘数据,并利用gzip工具进行压缩,保存到指定路径:dd if=/dev/hdx | gzip >/path/to/image.gz
将备份文件恢复到指定盘:dd if=/path/to/image of=/dev/hdx
将压缩的备份文件恢复到指定盘 :gzip -dc /path/to/image.gz | dd of=/dev/hdx

2.fio硬盘压力测试
fio测试工具支持同步(pread/pwrite)和异步(libaio)FIO是测试IOPS的非常好的工具,用来对硬件进行压力测试和验证,支持13种不同的I/O引擎,包括:sync,mmap, libaio, posixaio, SG v3, splice, null, network, syslet, guasi, solarisaio 等等。
fio 官网地址:
http://freshmeat.net/projects/fio/
安装  
yum -y install libaio libaio-devel
wget http://brick.kernel.dk/snaps/fio-2.1.7.tar.bz2
tar xf fio-2.1.7.tar.bz2
cd fio-2.1.7/
./configure
make -j10
make install

测试案例介绍:
######################## 同步i/o ##################################################################3
同步i/o、顺序读:
fio -filename=/dev/rbd2 -direct=1 -iodepth 1 -thread -rw=read -ioengine=psync -bs=16k -size=50G -numjobs=30 -runtime=1000 -group_reporting -name=read-psync >read-psync.txt

同步i/o、顺序写:
fio -filename=/dev/rbd2 -direct=1 -iodepth 1 -thread -rw=write -ioengine=psync -bs=16k -size=50G -numjobs=30 -runtime=1000 -group_reporting -name=write-psync >write-psync.txt

同步i/o、顺序混合读写:
fio -filename=/dev/rbd2 -direct=1 -iodepth 1 -thread -rw=readwrite -rwmixread=50 -ioengine=psync -bs=16k -size=50G -numjobs=30 -runtime=1000 -group_reporting -name=rw-readwrite rw-readwrite-psync.txt

同步i/o、随机读:
fio -filename=/dev/rbd2 -direct=1 -iodepth 1 -thread -rw=randread -ioengine=psync -bs=16k -size=50G -numjobs=30 -runtime=1000 -group_reporting -name=randread-psync >randread-psync.txt

同步i/o、随机写:
fio -filename=/dev/rbd2 -direct=1 -iodepth 1 -thread -rw=randwrite -ioengine=psync -bs=16k -size=50G -numjobs=30 -runtime=1000 -group_reporting -name=randwrite-psync >randwrite-psync.txt

同步i/o、随机混合读写:
fio -filename=/dev/rbd2 -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=50 -ioengine=psync -bs=16k -size=50G -numjobs=30 -runtime=100 -group_reporting -ioscheduler=noop -name=randrw-psync >randrw-psync.txt

######################## 异步 i/o ##################################################################3
#异步 i/o、顺序读: fio -filename=/dev/rbd2 -direct=1 -iodepth 1 -thread -rw=read -ioengine=libaio -bs=16k -size=50G -numjobs=30 -runtime=1000 -group_reporting -name=read-libaio >read-libaio.txt

异步 i/o、顺序写:
fio -filename=/dev/rbd2 -direct=1 -iodepth 1 -thread -rw=write -ioengine=libaio -bs=16k -size=50G -numjobs=30 -runtime=1000 -group_reporting -name=write-libaio >write-libaio.txt

异步 i/o、顺序混合读写:
fio -filename=/dev/rbd2 -direct=1 -iodepth 1 -thread -rw=readwrite -rwmixread=50 -ioengine=libaio -bs=16k -size=50G -numjobs=30 -runtime=1000 -group_reporting -name=rw-readwrite-libaio >rw-readwrite-psync.txt

异步 i/o、随机读:
fio -filename=/dev/rbd2 -direct=1 -iodepth 1 -thread -rw=randread -ioengine=libaio -bs=16k -size=50G -numjobs=30 -runtime=1000 -group_reporting -name=randread-libaio >randread-libaio.txt

异步 i/o、随机写:
fio -filename=/dev/rbd2 -direct=1 -iodepth 1 -thread -rw=randwrite -ioengine=libaio -bs=16k -size=50G -numjobs=30 -runtime=1000 -group_reporting -name=randwrite-libaio >randwrite-libaio.txt

异步 i/o、随机混合读写:
fio -filename=/dev/rbd2 -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=50 -ioengine=libaio -bs=16k -size=50G -numjobs=30 -runtime=100 -group_reporting -ioscheduler=noop -name=randrw-libaio >randrw-libaio.txt
说明:
filename=/dev/rbd2 测试文件名称,需要测试的盘的某目录。
direct=1 测试过程绕过机器自带的buffer。使测试结果更真实。
{ read 顺序读 write 顺序写 randwrite 随机写 randread 随机读 rw,readwrite 顺序混合读写 randrw 随机混合读写 }
bs=16k 单次io的块文件大小为16k
bsrange=512-2048 同上,提定数据块的大小范围
size=5g 本次的测试文件大小为5g,以每次4k的io进行测试。
numjobs=30 本次的测试线程为30.
runtime=1000 测试时间为1000秒,如果不写则一直将5g文件分4k每次写完为止。
ioengine=psync io引擎使用pync方式
rwmixread=30 在混合读写的模式下,读占30% ,默认%50,两个参数同时使用,后者覆盖第一
rwmixwrite=30 在混合读写的模式下,写占30% ,默认%50
group_reporting 关于显示结果的,汇总每个进程的信息。
lockmem=1g 只使用1g内存进行测试。
zero_buffers 用0初始化系统buffer。
nrfiles=8 每个进程生成文件的数量。
ioscheduler 尝试切换设备托管文件指定的I / O调度器。
psync 同步i/o测试
libaio 异步i/o测试
libaio的读写过程简单说来就是你发出一个读写请求,然后你可以开始做其他事情,当读写过程结束时libaio会通知你你的这次请求已经完成。


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表