dd命令能粗略測試硬盤IO性能,但是執行dd命令測試硬盤IO性能,對硬盤的損害很大,不建議多次或長時間嘗試.
[root@localhost /]# time dd if=/dev/zero of=/dev/null bs=4k count=256000
256000+0 records in
256000+0 records out
1048576000 bytes (1.0 GB) copied, 0.782804 s, 1.3 GB/s
real 0m0.786s
user 0m0.160s
sys 0m0.626s
[root@localhost /]# time dd if=/dev/zero of=/dev/null bs=4k count=256000 oflag=dsync
256000+0 records in
256000+0 records out
1048576000 bytes (1.0 GB) copied, 0.758887 s, 1.4 GB/s
real 0m0.762s
user 0m0.120s
sys 0m0.642s
[root@localhost /]# time dd if=/dev/zero of=/dev/null bs=4k count=256000 conv=fdatasync
dd: fsync failed for ‘/dev/null’: Invalid argument
256000+0 records in
256000+0 records out
1048576000 bytes (1.0 GB) copied, 0.514259 s, 2.0 GB/s
real 0m0.518s
user 0m0.128s
sys 0m0.390s
[root@localhost /]#
oflag=dsync:dd會從/dev/zero中,每次讀取4Kbytes數據,然後直接寫入到硬盤當中,重複此步驟,直到共讀取並且寫入了1 Gbytes的數據。這個過程可能會很慢,因爲沒有用到寫緩存(write cache),加此參數,可以模擬數據庫的插入操作,可能跟接近真實。
conv=fdatasync:dd會從/dev/zero中一次性讀取1 Gbytes的數據,寫入到磁盤的緩存中,然後再從磁盤緩存中讀取,一次性寫入到硬盤當中。
time命令用來計算dd程序的運行耗時(real), 用戶態cpu耗時(user), 系統態cpu耗時(sys)。
real : 表示foo程序整個的運行耗時。可以理解爲foo運行開始時刻你看了一下手錶,foo運行結束時,你又看了一下手錶,兩次時間的差值就是本次real 代表的值
user:這個時間代表的是foo運行在用戶態的cpu時間,
sys: 這個時間代表的是foo運行在覈心態的cpu時間。