Linux磁碟I/O效能測試
阿新 • • 發佈:2019-02-16
磁碟效能評價指標
IOPS:(Input/Output Per Second)每秒的讀寫次數,隨機讀寫關注指標,是隨機讀寫頻繁的應用,如OLTP(Online Transaction Processing),的關鍵衡量指標。
吞吐量:(Throughput)單位時間內可以成功傳輸的資料數量,也稱作傳輸頻寬(bandwidth),順序讀寫關注指標,對於大量順序讀寫的應用,如VOD(Video On Demand),則更關注吞吐量指標。
IOPS和吞吐量之間關係:Throughput MB/s = IOPS * KB per IO / 1024
,即吞吐量等於IOPS乘以每次IO大小,理論上磁碟可以處理不同的IO大小(如512B、4KB、8KB、16KB),所能達到的Throughput吞吐量是有區別的。簡單的來說,物理層面IOPS和Throughput哪個先達到了物理磁碟的極限,就決定了這個物理磁碟的效能閥值。
測試專案
順序讀寫、隨機讀寫、混合讀寫
測試工具
dd(device to device)命令、fio、hdparm、IOMeter
使用舉例
hdparm(比較簡單)
# hdparm -tT /dev/nvme0n1
/dev/nvme0n1:
Timing cached reads: 15696 MB in 2.00 seconds = 7866.33 MB/sec
Timing buffered disk reads: 7506 MB in 3.00 seconds = 2501.42 MB/sec
能夠看到 2 秒內讀取了 15696MB快取,而在 3 秒內從磁碟上物理讀 7506MB 資料
fio(比較全面)
sudo fio -ioengine=libaio -bs=4k -direct=1 -thread -rw=read -filename=/dev/sda2 -name="BS 4KB read test" -iodepth=16 -runtime=60
順序寫(寫filename設定為磁碟,不是分割槽)
sudo fio -ioengine=libaio -bs=4k -direct=1 -thread -rw=write -filename=/dev/sdb -name="BS 4KB read test" -iodepth=16 -runtime=60
隨機讀
sudo fio -ioengine=libaio -bs=4k -direct=1 -thread -rw=randread -filename=/dev/sdb -name="BS 4KB read test" -iodepth=16 -runtime=60
隨機寫
sudo fio -ioengine=libaio -bs=4k -direct=1 -thread -rw=randwrite -filename=/dev/sdb -name="BS 4KB read test" -iodepth=16 -runtime=60
混合讀寫
sudo fio -ioengine=libaio -bs=4k -direct=1 -thread -rw=randrw -rwmixread=70 -filename=/dev/sdb -name="BS 4KB randrw 70 test" -iodepth=16 -runtime=60
結果分析: