如何在Linux中使用Fio來測評硬盤性能
Fio(Flexible I/O Tester) 是一款由 Jens Axboe 開發(fā)的用于測評和壓力/硬件驗(yàn)證的自由開源的軟件。
它支持 19 種不同類型的 I/O 引擎 (sync、mmap、libaio、posixaio、SG v3、splice、null、network、 syslet、guasi、solarisaio,以及更多), I/O 優(yōu)先級(針對較新的 Linux 內(nèi)核),I/O 速度,fork 的任務(wù)或線程任務(wù)等等。它能夠在塊設(shè)備和文件上工作。
Fio 接受一種非常簡單易于理解的文本格式的任務(wù)描述。軟件默認(rèn)包含了幾個(gè)示例任務(wù)文件。 Fio 展示了所有類型的 I/O 性能信息,包括完整的 IO 延遲和百分比。
它被廣泛的應(yīng)用在非常多的地方,包括測評、QA,以及驗(yàn)證用途。它支持 Linux 、FreeBSD 、NetBSD、 OpenBSD、 OS X、 OpenSolaris、 AIX、 HP-UX、 Android 以及 Windows。
在這個(gè)教程,我們將使用 Ubuntu 16 ,你需要擁有這臺(tái)電腦的 sudo
或 root 權(quán)限。我們將完整的進(jìn)行安裝和 Fio 的使用。
使用源碼安裝 Fio
我們要去克隆 GitHub 上的倉庫。安裝所需的依賴,然后我們將會(huì)從源碼構(gòu)建應(yīng)用。首先,確保我們安裝了 Git 。
sudo apt-get install git
CentOS 用戶可以執(zhí)行下述命令:
sudo yum install git
現(xiàn)在,我們切換到 /opt
目錄,并從 Github 上克隆倉庫:
cd /opt
git clone https://github.com/axboe/fio
你應(yīng)該會(huì)看到下面這樣的輸出:
Cloning into 'fio'...
remote: Counting objects: 24819, done.
remote: Compressing objects: 100% (44/44), done.
remote: Total 24819 (delta 39), reused 62 (delta 32), pack-reused 24743
Receiving objects: 100% (24819/24819), 16.07 MiB | 0 bytes/s, done.
Resolving deltas: 100% (16251/16251), done.
Checking connectivity... done.
現(xiàn)在,我們通過在 /opt
目錄下輸入下方的命令切換到 Fio 的代碼目錄:
cd fio
***,我們可以使用下面的命令來使用 make
從源碼構(gòu)建軟件:
# ./configure
# make
# make install
在 Ubuntu 上安裝 Fio
對于 Ubuntu 和 Debian 來說, Fio 已經(jīng)在主倉庫內(nèi)。你可以很容易的使用類似 yum
和 apt-get
的標(biāo)準(zhǔn)包管理器來安裝 Fio。
對于 Ubuntu 和 Debian ,你只需要簡單的執(zhí)行下述命令:
sudo apt-get install fio
對于 CentOS/Redhat 你只需要簡單執(zhí)行下述命令。
在 CentOS ,你可能在你能安裝 Fio 前需要去安裝 EPEL 倉庫到你的系統(tǒng)中。你可以通過執(zhí)行下述命令來安裝它:
sudo yum install epel-release -y
你可以執(zhí)行下述命令來安裝 Fio:
sudo yum install fio -y
使用 Fio 進(jìn)行磁盤性能測試
現(xiàn)在 Fio 已經(jīng)安裝到了你的系統(tǒng)中。現(xiàn)在是時(shí)候看一些如何使用 Fio 的例子了。我們將進(jìn)行隨機(jī)寫、讀和讀寫測試。
執(zhí)行隨機(jī)寫測試
執(zhí)行下面的命令來開始。這個(gè)命令將要同一時(shí)間執(zhí)行兩個(gè)進(jìn)程,寫入共計(jì) 4GB( 4 個(gè)任務(wù) x 512MB = 2GB) 文件:
sudo fio --name=randwrite --ioengine=libaio --iodepth=1 --rw=randwrite --bs=4k --direct=0 --size=512M --numjobs=2 --runtime=240 --group_reporting
...
fio-2.2.10
Starting 2 processes
randwrite: (groupid=0, jobs=2): err= 0: pid=7271: Sat Aug 5 13:28:44 2017
write: io=1024.0MB, bw=2485.5MB/s, iops=636271, runt= 412msec
slat (usec): min=1, max=268, avg= 1.79, stdev= 1.01
clat (usec): min=0, max=13, avg= 0.20, stdev= 0.40
lat (usec): min=1, max=268, avg= 2.03, stdev= 1.01
clat percentiles (usec):
| 1.00th=[ 0], 5.00th=[ 0], 10.00th=[ 0], 20.00th=[ 0],
| 30.00th=[ 0], 40.00th=[ 0], 50.00th=[ 0], 60.00th=[ 0],
| 70.00th=[ 0], 80.00th=[ 1], 90.00th=[ 1], 95.00th=[ 1],
| 99.00th=[ 1], 99.50th=[ 1], 99.90th=[ 1], 99.95th=[ 1],
| 99.99th=[ 1]
lat (usec) : 2=99.99%, 4=0.01%, 10=0.01%, 20=0.01%
cpu : usr=15.14%, sys=84.00%, ctx=8, majf=0, minf=26
IO depths : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
issued : total=r=0/w=262144/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
latency : target=0, window=0, percentile=100.00%, depth=1
Run status group 0 (all jobs):
WRITE: io=1024.0MB, aggrb=2485.5MB/s, minb=2485.5MB/s, maxb=2485.5MB/s, mint=412msec, maxt=412msec
Disk stats (read/write):
sda: ios=0/0, merge=0/0, ticks=0/0, in_queue=0, util=0.00%
執(zhí)行隨機(jī)讀測試
我們將要執(zhí)行一個(gè)隨機(jī)讀測試,我們將會(huì)嘗試讀取一個(gè)隨機(jī)的 2GB 文件。
sudo fio --name=randread --ioengine=libaio --iodepth=16 --rw=randread --bs=4k --direct=0 --size=512M --numjobs=4 --runtime=240 --group_reporting
你應(yīng)該會(huì)看到下面這樣的輸出:
...
fio-2.2.10
Starting 4 processes
randread: Laying out IO file(s) (1 file(s) / 512MB)
randread: Laying out IO file(s) (1 file(s) / 512MB)
randread: Laying out IO file(s) (1 file(s) / 512MB)
randread: Laying out IO file(s) (1 file(s) / 512MB)
Jobs: 4 (f=4): [r(4)] [100.0% done] [71800KB/0KB/0KB /s] [17.1K/0/0 iops] [eta 00m:00s]
randread: (groupid=0, jobs=4): err= 0: pid=7586: Sat Aug 5 13:30:52 2017
read : io=2048.0MB, bw=80719KB/s, iops=20179, runt= 25981msec
slat (usec): min=72, max=10008, avg=195.79, stdev=94.72
clat (usec): min=2, max=28811, avg=2971.96, stdev=760.33
lat (usec): min=185, max=29080, avg=3167.96, stdev=798.91
clat percentiles (usec):
| 1.00th=[ 2192], 5.00th=[ 2448], 10.00th=[ 2576], 20.00th=[ 2736],
| 30.00th=[ 2800], 40.00th=[ 2832], 50.00th=[ 2928], 60.00th=[ 3024],
| 70.00th=[ 3120], 80.00th=[ 3184], 90.00th=[ 3248], 95.00th=[ 3312],
| 99.00th=[ 3536], 99.50th=[ 6304], 99.90th=[15168], 99.95th=[18816],
| 99.99th=[22912]
bw (KB /s): min=17360, max=25144, per=25.05%, avg=20216.90, stdev=1605.65
lat (usec) : 4=0.01%, 10=0.01%, 250=0.01%, 500=0.01%, 750=0.01%
lat (usec) : 1000=0.01%
lat (msec) : 2=0.01%, 4=99.27%, 10=0.44%, 20=0.24%, 50=0.04%
cpu : usr=1.35%, sys=5.18%, ctx=524309, majf=0, minf=98
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=100.0%, 32=0.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.1%, 32=0.0%, 64=0.0%, >=64=0.0%
issued : total=r=524288/w=0/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
latency : target=0, window=0, percentile=100.00%, depth=16
Run status group 0 (all jobs):
READ: io=2048.0MB, aggrb=80718KB/s, minb=80718KB/s, maxb=80718KB/s, mint=25981msec, maxt=25981msec
Disk stats (read/write):
sda: ios=521587/871, merge=0/1142, ticks=96664/612, in_queue=97284, util=99.85%
***,我們想要展示一個(gè)簡單的隨機(jī)讀-寫測試來看一看 Fio 返回的輸出類型。
讀寫性能測試
下述命令將會(huì)測試 USB Pen 驅(qū)動(dòng)器 (/dev/sdc1
) 的隨機(jī)讀寫性能:
sudo fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=random_read_write.fio --bs=4k --iodepth=64 --size=4G --readwrite=randrw --rwmixread=75
下面的內(nèi)容是我們從上面的命令得到的輸出:
fio-2.2.10
Starting 1 process
Jobs: 1 (f=1): [m(1)] [100.0% done] [217.8MB/74452KB/0KB /s] [55.8K/18.7K/0 iops] [eta 00m:00s]
test: (groupid=0, jobs=1): err= 0: pid=8475: Sat Aug 5 13:36:04 2017
read : io=3071.7MB, bw=219374KB/s, iops=54843, runt= 14338msec
write: io=1024.4MB, bw=73156KB/s, iops=18289, runt= 14338msec
cpu : usr=6.78%, sys=20.81%, ctx=1007218, majf=0, minf=9
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=0.1%, >=64=100.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.1%, >=64=0.0%
issued : total=r=786347/w=262229/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
latency : target=0, window=0, percentile=100.00%, depth=64
Run status group 0 (all jobs):
READ: io=3071.7MB, aggrb=219374KB/s, minb=219374KB/s, maxb=219374KB/s, mint=14338msec, maxt=14338msec
WRITE: io=1024.4MB, aggrb=73156KB/s, minb=73156KB/s, maxb=73156KB/s, mint=14338msec, maxt=14338msec
Disk stats (read/write):
sda: ios=774141/258944, merge=1463/899, ticks=748800/150316, in_queue=900720, util=99.35%
我們希望你能喜歡這個(gè)教程并且享受接下來的內(nèi)容,F(xiàn)io 是一個(gè)非常有用的工具,并且我們希望你能在你下一次 Debugging 活動(dòng)中使用到它。如果你喜歡這個(gè)文章,歡迎留下評論和問題。