Linux测试硬盘性能的脚本

大家都知道在linux下可以使用dd命令,测试硬盘的读写速度,从/dev/zero 读入数据,写到硬盘中。但实际应用中,硬盘的读写速度和块的大小是有很大关系的,所以最好是使用不同的块进行测试。Windows下的Atto Disk Benchmark就进行了一系列的测试。

 

下面的脚本模仿Atto Disk Benchmark的方法,用不同的块大小,写入数据,并使用direct模式写入,从而测试硬盘的性能。

#!/bin/bash
# Test disk write speed with dd, with different bs , 2GB data
 
BS=(512 1k 2k 4k 8k 16k 32k 64k 128k 256k 512k 1M 2M 4M 8M 12M 16M 24M 32M 48M 64M)
#COUNT_2G=(4000000 2000000 1000000 500000 250000 125000 62500 31250 15625 7813 3907 1954 977 489 245 163 123 82 62 41 31)
# reduce count for small BS < 4k
COUNT_2G=( 400000  200000  100000  500000 250000 125000 62500 31250 15625 7813 3907 1954 977 489 245 163 123 82 62 41 31)
FILE=file.tst 

for id in $(seq ${#BS[*]}) ; do
  rm -rf $FILE 2>1 1>/dev/null
  sleep 3 

  idx=`expr $id - 1`
  echo ---- $id: bs=${BS[$idx]},  ${COUNT_2G[$idx]}  --------
  dd if=/dev/zero of=$FILE bs=${BS[$idx]} count=${COUNT_2G[$idx]} oflag=direct 

done

以下是运行的结果。

---- 1: bs=512, 400000 --------
400000+0 records in
400000+0 records out
204800000 bytes (205 MB, 195 MiB) copied, 62.7505 s, 3.3 MB/s
---- 2: bs=1k, 200000 --------
200000+0 records in
200000+0 records out
204800000 bytes (205 MB, 195 MiB) copied, 32.2108 s, 6.4 MB/s
---- 3: bs=2k, 100000 --------
100000+0 records in
100000+0 records out
204800000 bytes (205 MB, 195 MiB) copied, 16.727 s, 12.2 MB/s
---- 4: bs=4k, 500000 --------
500000+0 records in
500000+0 records out
2048000000 bytes (2.0 GB, 1.9 GiB) copied, 83.7712 s, 24.4 MB/s
---- 5: bs=8k, 250000 --------
250000+0 records in
250000+0 records out
2048000000 bytes (2.0 GB, 1.9 GiB) copied, 46.0615 s, 44.5 MB/s
---- 6: bs=16k, 125000 --------
125000+0 records in
125000+0 records out
2048000000 bytes (2.0 GB, 1.9 GiB) copied, 24.6359 s, 83.1 MB/s
---- 7: bs=32k, 62500 --------
62500+0 records in
62500+0 records out
2048000000 bytes (2.0 GB, 1.9 GiB) copied, 14.0071 s, 146 MB/s
---- 8: bs=64k, 31250 --------
31250+0 records in
31250+0 records out
2048000000 bytes (2.0 GB, 1.9 GiB) copied, 8.68906 s, 236 MB/s
---- 9: bs=128k, 15625 --------
15625+0 records in
15625+0 records out
2048000000 bytes (2.0 GB, 1.9 GiB) copied, 6.01973 s, 340 MB/s
---- 10: bs=256k, 7813 --------
7813+0 records in
7813+0 records out
2048131072 bytes (2.0 GB, 1.9 GiB) copied, 4.49103 s, 456 MB/s
---- 11: bs=512k, 3907 --------
3907+0 records in
3907+0 records out
2048393216 bytes (2.0 GB, 1.9 GiB) copied, 3.72429 s, 550 MB/s
---- 12: bs=1M, 1954 --------
1954+0 records in
1954+0 records out
2048917504 bytes (2.0 GB, 1.9 GiB) copied, 2.96562 s, 691 MB/s
---- 13: bs=2M, 977 --------
977+0 records in
977+0 records out
2048917504 bytes (2.0 GB, 1.9 GiB) copied, 3.01407 s, 680 MB/s
---- 14: bs=4M, 489 --------
489+0 records in
489+0 records out
2051014656 bytes (2.1 GB, 1.9 GiB) copied, 3.13079 s, 655 MB/s
---- 15: bs=8M, 245 --------
245+0 records in
245+0 records out
2055208960 bytes (2.1 GB, 1.9 GiB) copied, 3.17717 s, 647 MB/s
---- 16: bs=12M, 163 --------
163+0 records in
163+0 records out
2051014656 bytes (2.1 GB, 1.9 GiB) copied, 3.21507 s, 638 MB/s
---- 17: bs=16M, 123 --------
123+0 records in
123+0 records out
2063597568 bytes (2.1 GB, 1.9 GiB) copied, 3.25448 s, 634 MB/s
---- 18: bs=24M, 82 --------
82+0 records in
82+0 records out
2063597568 bytes (2.1 GB, 1.9 GiB) copied, 3.249 s, 635 MB/s
---- 19: bs=32M, 62 --------
62+0 records in
62+0 records out
2080374784 bytes (2.1 GB, 1.9 GiB) copied, 3.309 s, 629 MB/s
---- 20: bs=48M, 41 --------
41+0 records in
41+0 records out
2063597568 bytes (2.1 GB, 1.9 GiB) copied, 4.20253 s, 491 MB/s
---- 21: bs=64M, 31 --------
31+0 records in
31+0 records out
2080374784 bytes (2.1 GB, 1.9 GiB) copied, 4.48494 s, 464 MB/s

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值