linux禁用cache,测试写性能,IO性能测试及cache对读写性能的影响

dd只能提供一个大概的测试结果,而且是连续IO 而不是随机IO ,理论上文件规模越大,测试结果越准确。

Linux下对文件的访问和设备的访问通常会被cache起来加快访问速度,这个是系统的默认行为

写测试 (直接落盘,不通过cache)

[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

写测试 (通过cache)

[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

读写 (不通过cache)

[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

cache对性能的影响:

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上,也相当于测试磁盘的读能力。

写测试

# time dd oflag=direct,nonblock if=/dev/zero of=/opt/iotest bs=8k count=100000

因为/dev/zero是一个伪设备,它只产生空字符流,对它不会产生IO,

所以,IO都会集中在of文件中,of文件只用于写,所以这个命令相当于测试磁盘的写能力。

读写测试

# 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的影响

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值