dd只能提供一个大概的测试结果,并且是连续IO 而不是随机IO ,理论上文件规模越大,测试结果越准确。
Linux下对文件的访问和设备的访问一般会被cache起来加快访问速度,这个是系统的默认行为centos
[root@centos-FI ~]# time dd oflag=direct,nonblock if=/dev/zero of=/opt/iotest bs=8k count=100000 100000+0 records in 100000+0 records out 819200000 bytes (819 MB) copied, 20.7926 s, 39.4 MB/s real 0m20.873s user 0m0.012s sys 0m7.226s
[root@centos-FI ~]# time dd if=/dev/zero of=/opt/iotest2 bs=8k count=100000 100000+0 records in 100000+0 records out 819200000 bytes (819 MB) copied, 11.9159 s, 68.7 MB/s real 0m11.948s user 0m0.028s sys 0m1.913s
[root@centos-FI ~]# time dd oflag=direct,nonblock iflag=direct,nonblock if=/opt/iotest2 of=/opt/iotest3 bs=8k count=100000 100000+0 records in 100000+0 records out 819200000 bytes (819 MB) copied, 114.291 s, 7.2 MB/s real 1m54.292s user 0m0.017s sys 0m14.401s
cmd | result |
---|---|
dd oflag=direct,nonblock if=/dev/zero of=/opt/iotest bs=8k count=100000 | 39.4 MB/s |
dd if=/dev/zero of=/opt/iotest2 bs=8k count=100000 | 68.7 MB/s |
dd oflag=direct,nonblock iflag=direct,nonblock if=/opt/iotest2 of=/opt/iotest3 bs=8k count=100000 | 7.2 MB/s缓存 |
读性能测试性能
# time dd iflag=direct,nonblock if=/dev/sda2 of=/dev/null bs=8k count=100000
由于/dev/sda2是一个物理分区,对它的读取会产生IO,/dev/null是伪设备,至关于黑洞,of到该设备不会产生IO,
因此,这个命令的IO只发生在/dev/sdb1上,也至关于测试磁盘的读能力。测试
写测试spa
# time dd oflag=direct,nonblock if=/dev/zero of=/opt/iotest bs=8k count=100000
由于/dev/zero是一个伪设备,它只产生空字符流,对它不会产生IO,
因此,IO都会集中在of文件中,of文件只用于写,因此这个命令至关于测试磁盘的写能力。操作系统
读写测试code
# time dd iflag=direct,nonblock oflag=direct,nonblock if=/dev/sda2 of=/opt/iotest bs=8k count=100000
说明:
bs是一次io读的规模,理论上bs越大,所测得性能越高
count是读多少个"bs",也能够写成count=16G
direct 模式就是把写入请求直接封装成io 指令发到磁盘
非direct 模式,就把数据写入系统缓存,而后就认为io 成功,并由操做系统决定缓存中的数据何时被写入磁盘
参数oflag和iflag, 控制源文件和目标文件的读写方式为direct IO,即读或写文件时越过操做系统的读写buffer。
若是指定oflag=direct,nonblock,写文件时忽略cache的影响;
而若是指定iflag=direct,nonblock,读文件时忽略cache的影响cmd