FIO是測試IOPS的非常好的工具,用來對硬件進行壓力測試和驗證。磁盤IO是檢查磁盤性能的重要指標,可以按照負載情況分成照順序讀寫,隨機讀寫兩大類。
目前主流的第三方IO測試工具有fio、iometer 和 Orion,這三種工具各有千秋,在linux 下也可以使用dd 進行簡單的磁盤(文件系統)測試(文末補充)。
fio在Linux系統下使用比較方便,iometer在window系統下使用比較方便,Orion是oracle的IO測試軟件,可在沒有安裝oracle數據庫的情況下模擬oracle數據庫場景的讀寫。
Multithreaded IO generation tool , FIO 是一個多線程io生成工具,可以生成多種IO模式,用來測試磁盤設備的性能(也包含文件系統:如針對網絡文件系統 NFS 的IO測試);
Description : fio is an I/O tool that will spawn a number of threads or processes doing
: a particular type of io action as specified by the user. fio takes a
: number of global parameters, each inherited by the thread unless
: otherwise parameters given to them overriding that setting is given.
: The typical use of fio is to write a job file matching the io load
: one wants to simulate.
安裝:
yum install fio yum info fio
項目地址:
https://github.com/axboe/fio.git
http://git.kernel.dk/cgit/fio/
磁盤處理:
fio 用於測試磁盤性能時,測試之前需要先把要測試的磁盤卸載掉,測試完后需格式化一遍再掛載上去。
# 卸載磁盤 umount /mnt/datadir1 # 格式化磁盤 mkfs.ext4 /dev/sdd # 掛載磁盤 mount -t ext4 /dev/sdd /mnt/datadir1 # 自動掛載,在里面添加該盤 vim /etc/fstab
FIO 工具常用方法:
參數說明: filename=/dev/sdb1 測試文件名稱,通常選擇需要測試的盤的data目錄。 direct=1 測試過程繞過機器自帶的buffer。使測試結果更真實。 rw=randwrite 測試隨機寫的I/O rw=randrw 測試隨機寫和讀的I/O bs=16k 單次io的塊文件大小為16k bsrange=512-2048 同上,提定數據塊的大小范圍 size=5g 本次的測試文件大小為5g,以每次4k的io進行測試。 numjobs=30 本次的測試線程為30. runtime=1000 測試時間為1000秒,如果不寫則一直將5g文件分4k每次寫完為止。 ioengine=psync io引擎使用pync方式 rwmixwrite=30 在混合讀寫的模式下,寫占30% group_reporting 關於顯示結果的,匯總每個進程的信息。 此外 lockmem=1g 只使用1g內存進行測試。 zero_buffers 用0初始化系統buffer。 nrfiles=8 每個進程生成文件的數量。 磁盤讀寫常用測試點: 1. Read=100% Ramdon=100% rw=randread (100%隨機讀) 2. Read=100% Sequence=100% rw=read (100%順序讀) 3. Write=100% Sequence=100% rw=write (100%順序寫) 4. Write=100% Ramdon=100% rw=randwrite (100%隨機寫) 5. Read=70% Sequence=100% rw=rw, rwmixread=70, rwmixwrite=30 (70%順序讀,30%順序寫) 6. Read=70% Ramdon=100% rw=randrw, rwmixread=70, rwmixwrite=30 (70%隨機讀,30%隨機寫)
FIO 工具測試模式:
順序讀寫:
read 順序讀
write 順序寫
rw,readwrite 順序混合讀寫
隨機讀寫:
randwrite 隨機寫
randread 隨機讀
randrw 隨機混合讀寫
測試樣例:
[root@docker mnt]# fio -filename=/dev/sda -direct=1 -iodepth 1 -thread -rw=read -ioengine=psync -bs=16k -size=20G -numjobs=30 -runtime=1000 -group_reporting -name=yaoxu-sda
本文章,只是資料查找中的簡要摘錄,詳細使用說明,請參考 man fio
測試結果:(其中加粗的輸出日志,是我們關注的內容:磁盤的吞吐量bw,這個是順序讀寫考察的重點;磁盤的每秒讀寫次數iops,這個是隨機讀寫考察的重點)
[root@docker sda]# fio -ioengine=libaio -bs=4k -direct=1 -thread -rw=read -filename=/dev/sda -name="BS 4KB read test" -iodepth=16 -runtime=60 BS 4KB read test: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=16 fio-3.7 Starting 1 thread Jobs: 1 (f=1): [R(1)][100.0%][r=89.3MiB/s,w=0KiB/s][r=22.9k,w=0 IOPS][eta 00m:00s] BS 4KB read test: (groupid=0, jobs=1): err= 0: pid=18557: Thu Apr 11 13:08:11 2019 read: IOPS=22.7k, BW=88.5MiB/s (92.8MB/s)(5313MiB/60001msec) slat (nsec): min=901, max=168330, avg=6932.34, stdev=1348.82 clat (usec): min=90, max=63760, avg=698.08, stdev=240.83 lat (usec): min=97, max=63762, avg=705.17, stdev=240.81 clat percentiles (usec): | 1.00th=[ 619], 5.00th=[ 627], 10.00th=[ 627], 20.00th=[ 635], | 30.00th=[ 635], 40.00th=[ 685], 50.00th=[ 717], 60.00th=[ 725], | 70.00th=[ 725], 80.00th=[ 725], 90.00th=[ 734], 95.00th=[ 816], | 99.00th=[ 1004], 99.50th=[ 1020], 99.90th=[ 1057], 99.95th=[ 1057], | 99.99th=[ 1860] bw ( KiB/s): min=62144, max=91552, per=100.00%, avg=90669.02, stdev=3533.77, samples=120 iops : min=15536, max=22888, avg=22667.27, stdev=883.44, samples=120 lat (usec) : 100=0.01%, 250=0.01%, 500=0.01%, 750=93.85%, 1000=5.14% lat (msec) : 2=0.99%, 4=0.01%, 10=0.01%, 50=0.01%, 100=0.01% cpu : usr=5.35%, sys=23.17%, ctx=1359692, majf=0, minf=17 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 rwts: total=1360097,0,0,0 short=0,0,0,0 dropped=0,0,0,0 latency : target=0, window=0, percentile=100.00%, depth=16 Run status group 0 (all jobs): READ: bw=88.5MiB/s (92.8MB/s), 88.5MiB/s-88.5MiB/s (92.8MB/s-92.8MB/s), io=5313MiB (5571MB), run=60001-60001msec Disk stats (read/write): sda: ios=1357472/0, merge=70/0, ticks=949141/0, in_queue=948776, util=99.88%
io=執行了多少M的IO
bw=平均IO帶寬
iops=IOPS
runt=線程運行時間
slat=提交延遲
clat=完成延遲
lat=響應時間
bw=帶寬
cpu=利用率
IO depths=io隊列
IO submit=單個IO提交要提交的IO數
IO complete=Like the above submit number, but for completions instead.
IO issued=The number of read/write requests issued, and how many of them were short.
IO latencies=IO完延遲的分布
io=總共執行了多少size的IO
aggrb=group總帶寬
minb=最小.平均帶寬.
maxb=最大平均帶寬.
mint=group中線程的最短運行時間.
maxt=group中線程的最長運行時間.
ios=所有group總共執行的IO數.
merge=總共發生的IO合並數.
ticks=Number of ticks we kept the disk busy.
io_queue=花費在隊列上的總共時間.
util=磁盤利用率
fio 有很多測試任務配置文件,在git工程 examples 文件夾中,我們可以使用命令行參數進行直接配置,也可以直接通過配置文件配置一次測試的內容。
更詳細對fio輸出說明請參考博文:Fio Output Explained
IO狀態監控:
進行磁盤測試的時候,我們可以使用iostat 等監控工具,查看所有磁盤當前的讀寫狀態(fedora 系統上 sysstat-11.7.3-2.fc29.x86_64 收錄了此工具)。
監控磁盤IO命令:iostat –mx 1
avg-cpu: %user %nice %system %iowait %steal %idle 0.25 0.00 3.01 80.70 0.00 16.04 Device r/s w/s rMB/s wMB/s rrqm/s wrqm/s %rrqm %wrqm r_await w_await aqu-sz rareq-sz wareq-sz svctm %util sda 13417.00 0.00 209.64 0.00 0.00 0.00 0.00 0.00 2.23 0.00 29.96 16.00 0.00 0.07 100.00
rrqms:每秒這個設備相關的讀取請求有多少被Merge了(當系統調用需要讀取數據的時候,VFS將請求發到各個FS,如果FS發現不同的讀取請求讀取的是相同Block的數據,FS會將這個請求合並Merge) wrqm/s:每秒這個設備相關的寫入請求有多少被Merge了。 rsec/s:The number of sectors read from the device per second. wsec/s:The number of sectors written to the device per second. rKB/s:The number of kilobytes read from the device per second. wKB/s:The number of kilobytes written to the device per second. avgrq-sz:平均請求扇區的大小,The average size (in sectors) of the requests that were issued to the device. avgqu-sz:是平均請求隊列的長度。毫無疑問,隊列長度越短越好,The average queue length of the requests that were issued to the device. await:每一個IO請求的處理的平均時間(單位是微秒毫秒)。這里可以理解為IO的響應時間,一般地系統IO響應時間應該低於5ms,如果大於10ms就比較大了。 這個時間包括了隊列時間和服務時間,也就是說,一般情況下,await大於svctm,它們的差值越小,則說明隊列時間越短,反之差值越大,隊列時間越長,說明系統出了問題。 svctm:表示平均每次設備I/O操作的服務時間(以毫秒為單位)。如果svctm的值與await很接近,表示幾乎沒有I/O等待,磁盤性能很好。 如果await的值遠高於svctm的值,則表示I/O隊列等待太長,系統上運行的應用程序將變慢。 %util: 在統計時間內所有處理IO時間,除以總共統計時間。例如,如果統計間隔1秒,該設備有0.8秒在處理IO,而0.2秒閑置,那么該設備的%util = 0.8/1 = 80%, 所以該參數暗示了設備的繁忙程度,一般地,如果該參數是100%表示磁盤設備已經接近滿負荷運行了(當然如果是多磁盤,即使%util是100%,因為磁盤的並發能力,所以磁盤使用未必就到了瓶頸)。
更多關於磁盤順序io 部分,可以參考 dd 工具的使用;https://www.cnblogs.com/xuyaowen/p/dd.html
參考鏈接:
https://www.cnblogs.com/bugutian/p/6653083.html
https://www.linuxidc.com/Linux/2017-04/143251.htm
https://blog.csdn.net/jiecxy/article/details/58197387 (有很好的fio 輸出日志注釋,解釋了每行輸出內容的含義,建議閱讀。)
https://www.cnblogs.com/raykuan/p/6914748.html
https://blog.csdn.net/feng4656/article/details/11054595
https://tobert.github.io/post/2014-04-17-fio-output-explained.html
https://github.com/axboe/fio/blob/master/HOWTO
保持更新,轉載請注明出處。
