[转帖]dd 自动压测与结果解析脚本

测试串行、并发、读、写 4类操作,每类操作又可以指定各种bs及count值,循环压测。每种场景一般执行3次,取平均值。

一、 串行写


  1. #!/bin/sh
  2. bs_list=(256k 1024k 10M 20M 50M 100M 1G)
  3. cnt_list=(40000 10000 1000 500 200 100 10)
  4. for i in {0..6}
  5. do
  6. for j in {0..2}
  7. do
  8. logfile=dd_${bs_list[$i]}_cnt${cnt_list[$i]}_${j}.txt
  9. echo -e "test ${j} started\n" > $logfile
  10. echo -e "started time `date`\n" >> $logfile
  11. dd if=/dev/zero of=testfile1 bs=${bs_list[$i]} count=${cnt_list[$i]} oflag=direct,nonblock 2>> $logfile
  12. echo -e "\nfinished time `date`" >> $logfile
  13. echo -e "\ntest ${j} finished" >> $logfile
  14. sleep 5
  15. done
  16. sleep 30
  17. done

二、 4并发写


  1. #!/bin/sh
  2. # ddtest_write_conc.sh
  3. bs_list=(256k 1024k 10M 20M 50M 100M 1G)
  4. cnt_list=(40000 10000 1000 500 200 100 10)
  5. for i in {0..6}
  6. do
  7. for j in {0..2}
  8. do
  9. logfile=dd_conc_${bs_list[$i]}_cnt${cnt_list[$i]}_${j}.txt
  10. echo -e "test ${j} started\n" > $logfile
  11. echo -e "started time `date`\n" >> $logfile
  12. for conc in {0..3}
  13. do
  14. {
  15. dd if=/dev/zero of=testfile1 bs=${bs_list[$i]} count=${cnt_list[$i]} oflag=direct,nonblock 2>> $logfile
  16. } &
  17. done
  18. wait
  19. echo -e "\nfinished time `date`" >> $logfile
  20. echo -e "\ntest ${j} finished" >> $logfile
  21. sleep 5
  22. done
  23. sleep 30
  24. done

三、 串行读


  1. #!/bin/sh
  2. # ddtest_read_serial.sh
  3. bs_list=(256k 1024k 10M 20M 50M 100M 1G)
  4. cnt_list=(40000 10000 1000 500 200 100 10)
  5. for i in {0..6}
  6. do
  7. for j in {0..2}
  8. do
  9. logfile=dd_${bs_list[$i]}_cnt${cnt_list[$i]}_${j}.txt
  10. echo -e "test ${j} started\n" > $logfile
  11. echo -e "started time `date`\n" >> $logfile
  12. dd if=testfile1 of=/dev/null bs=${bs_list[$i]} count=${cnt_list[$i]} iflag=direct,nonblock 2>> $logfile
  13. echo -e "\nfinished time `date`" >> $logfile
  14. echo -e "\ntest ${j} finished" >> $logfile
  15. sleep 5
  16. done
  17. sleep 30
  18. done

四、 4并发读


  1. #!/bin/sh
  2. bs_list=(256k 1024k 10M 20M 50M 100M 1G)
  3. cnt_list=(40000 10000 1000 500 200 100 10)
  4. for i in {0..6}
  5. do
  6. for j in {0..2}
  7. do
  8. logfile=dd_conc_${bs_list[$i]}_cnt${cnt_list[$i]}_${j}.txt
  9. echo -e "test ${j} started\n" > $logfile
  10. echo -e "started time `date`\n" >> $logfile
  11. for conc in {0..3}
  12. do
  13. {
  14. dd if=testfile1 of=/dev/null bs=${bs_list[$i]} count=${cnt_list[$i]} iflag=direct,nonblock 2>> $logfile
  15. } &
  16. done
  17. wait
  18. echo -e "\nfinished time `date`" >> $logfile
  19. echo -e "\ntest ${j} finished" >> $logfile
  20. sleep 5
  21. done
  22. sleep 30
  23. done

五、 输出解析

取执行时间

cat dd_* | grep -E 'MB/s|GB/s' | awk '{ print $6 }'

取吞吐量

cat dd_* | grep -E 'MB/s|GB/s' | awk '{ print $8 }'