組件 | 版本 |
---|---|
OS | Ubuntu 16.04.4 LTS |
fio | 2.2.10 |
三、fio介紹
通過(guò)fio測(cè)試,能夠反映在讀寫中的狀態(tài),我們需要重點(diǎn)關(guān)注fio的輸出報(bào)告中的幾個(gè)關(guān)鍵指標(biāo):
slat :是指從 I/O 提交到實(shí)際執(zhí)行 I/O 的時(shí)長(zhǎng)(Submission latency)
clat :是指從 I/O 提交到 I/O 完成的時(shí)長(zhǎng)(Completion latency)
lat :指的是從 fio 創(chuàng)建 I/O 到 I/O 完成的總時(shí)長(zhǎng)
bw :吞吐量
iops :每秒 I/O 的次數(shù)
四、同步寫測(cè)試
(1)同步隨機(jī)寫
主要采用fio作為測(cè)試工具,為了能夠看到系統(tǒng)調(diào)用,使用strace工具,命令看起來(lái)是這樣:
先來(lái)測(cè)試一個(gè)隨機(jī)寫
strace -f -tt -o /tmp/randwrite.log -D fio -name=randwrite -rw=randwrite \ -direct=1 -bs=4k -size=1G -numjobs=1 -group_reporting -filename=/tmp/test.db
提取關(guān)鍵信息
root@wilson-ubuntu:~# strace -f -tt -o /tmp/randwrite.log -D fio -name=randwrite -rw=randwrite \ > -direct=1 -bs=4k -size=1G -numjobs=1 -group_reporting -filename=/tmp/test.db randwrite: (g=0): rw=randwrite, bs=4K-4K/4K-4K/4K-4K, ioengine=sync, iodepth=1 fio-2.2.10 Starting 1 process ... randwrite: (groupid=0, jobs=1): err= 0: pid=26882: Wed Aug 14 10:39:02 2019 write: io=1024.0MB, bw=52526KB/s, iops=13131, runt= 19963msec clat (usec): min=42, max=18620, avg=56.15, stdev=164.79 lat (usec): min=42, max=18620, avg=56.39, stdev=164.79 ... bw (KB /s): min=50648, max=55208, per=99.96%, avg=52506.03, stdev=1055.83 ... Run status group 0 (all jobs): WRITE: io=1024.0MB, aggrb=52525KB/s, minb=52525KB/s, maxb=52525KB/s, mint=19963msec, maxt=19963msec Disk stats (read/write): ... sda: ios=0/262177, merge=0/25, ticks=0/7500, in_queue=7476, util=36.05%
列出了我們需要重點(diǎn)關(guān)注的信息:
(1)clat ,平均時(shí)長(zhǎng)56ms左右
(2)lat ,平均時(shí)長(zhǎng)56ms左右
(3)bw ,吞吐量,大概在52M左右
再來(lái)看內(nèi)核調(diào)用信息:
root@wilson-ubuntu:~# more /tmp/randwrite.log ... 26882 10:38:41.919904 lseek(3, 665198592, SEEK_SET) = 665198592 26882 10:38:41.919920 write(3, "\220\240@\6\371\341\277>\0\200\36\31\0\0\0\0\202\2\7\320\343\6H\26P\340\277\370\330\30e\30"..., 4096) = 4096 26882 10:38:41.919969 lseek(3, 4313088, SEEK_SET) = 4313088 26882 10:38:41.919985 write(3, "\220\240@\6\371\341\277>\0\200\36\31\0\0\0\0\202\2\7\320\343\6H\26P\340\277\370\330\30e\30"..., 4096) = 4096 26882 10:38:41.920032 lseek(3, 455880704, SEEK_SET) = 455880704 26882 10:38:41.920048 write(3, "\220\240@\6\371\341\277>\0\200\36\31\0\0\0\0\202\2\7\320\343\6H\26P\340\277\370\330\30e\30"..., 4096) = 4096 26882 10:38:41.920096 lseek(3, 338862080, SEEK_SET) = 338862080 26882 10:38:41.920112 write(3, "\220\240@\6\371\341\277>\0\2402\24\0\0\0\0\202\2\7\320\343\6H\26P\340\277\370\330\30e\30"..., 4096) = 4096 26882 10:38:41.920161 lseek(3, 739086336, SEEK_SET) = 739086336 26882 10:38:41.920177 write(3, "\220\240@\6\371\341\277>\0\2402\24\0\0\0\0\202\2\7\320\343\6H\26P\340\277\370\330\30e\30"..., 4096) = 4096 26882 10:38:41.920229 lseek(3, 848175104, SEEK_SET) = 848175104 26882 10:38:41.920245 write(3, "\220\240@\6\371\341\277>\0\2402\24\0\0\0\0\202\2\7\320\343\6H\26P\340\277\370\330\30e\30"..., 4096) = 4096 26882 10:38:41.920296 lseek(3, 1060147200, SEEK_SET) = 1060147200 26882 10:38:41.920312 write(3, "\220\240@\6\371\341\277>\0\2402\24\0\0\0\0\202\2\7\320\343\6H\26P\340\277\370\330\30e\30"..., 4096) = 4096 26882 10:38:41.920362 lseek(3, 863690752, SEEK_SET) = 863690752 26882 10:38:41.920377 write(3, "\220\240@\6\371\341\277>\0\2402\24\0\0\0\0\202\2\7\320\343\6H\26P\340\277\370\330\30e\30"..., 4096) = 4096 26882 10:38:41.920428 lseek(3, 279457792, SEEK_SET) = 279457792 26882 10:38:41.920444 write(3, "\220\240@\6\371\341\277>\0\2402\24\0\0\0\0\202\2\7\320\343\6H\26P\340\277\370\330\30e\30"..., 4096) = 4096 26882 10:38:41.920492 lseek(3, 271794176, SEEK_SET) = 271794176 26882 10:38:41.920508 write(3, "\220\240@\6\371\341\277>\0\2402\24\0\0\0\0\202\2\7\320\343\6H\26P\340\277\370\330\30e\30"..., 4096) = 4096 26882 10:38:41.920558 lseek(3, 1067864064, SEEK_SET) = 1067864064 26882 10:38:41.920573 write(3, "\220\240@\6\371\341\277>\0\2402\24\0\0\0\0\202\2\7\320\343\6H\26P\340\277\370\330\30e\30"..., 4096) = 4096 ...
隨機(jī)讀每一次寫入之前都要通過(guò)lseek去定位當(dāng)前的文件偏移量
同步順序?qū)?/strong>
用剛才的方法來(lái)測(cè)試順序?qū)?/p>
root@wilson-ubuntu:~# strace -f -tt -o /tmp/write.log -D fio -name=write -rw=write \ -direct=1 -bs=4k -size=1G -numjobs=1 -group_reporting -filename=/tmp/test.db write: (g=0): rw=write, bs=4K-4K/4K-4K/4K-4K, ioengine=sync, iodepth=1 fio-2.2.10 Starting 1 process Jobs: 1 (f=1): [W(1)] [100.0% done] [0KB/70432KB/0KB /s] [0/17.7K/0 iops] [eta 00m:00s] write: (groupid=0, jobs=1): err= 0: pid=27005: Wed Aug 14 10:53:02 2019 write: io=1024.0MB, bw=70238KB/s, iops=17559, runt= 14929msec clat (usec): min=43, max=7464, avg=55.95, stdev=56.24 lat (usec): min=43, max=7465, avg=56.15, stdev=56.25 ... bw (KB /s): min=67304, max=72008, per=99.98%, avg=70225.38, stdev=1266.88 ... Run status group 0 (all jobs): WRITE: io=1024.0MB, aggrb=70237KB/s, minb=70237KB/s, maxb=70237KB/s, mint=14929msec, maxt=14929msec Disk stats (read/write): ... sda: ios=0/262162, merge=0/10, ticks=0/6948, in_queue=6932, util=46.49%
可以看到:
吞吐量提升至70M左右
再來(lái)看一下內(nèi)核調(diào)用:
root@wilson-ubuntu:~# more /tmp/write.log ... 27046 10:54:28.194508 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\360\t\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.194568 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.194627 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.194687 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.194747 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.194807 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.194868 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.194928 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.194988 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195049 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195110 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195197 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195262 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195330 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195426 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195497 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195567 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195637 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195704 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195757 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195807 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195859 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195910 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.195961 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.196012 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.196062 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0\220\24\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.196112 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0 \26\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.196162 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0 \26\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.196213 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0 \26\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.196265 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0 \26\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.196314 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0 \26\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.196363 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0 \26\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.196414 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0 \26\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.196472 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0 \26\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.196524 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0 \26\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 27046 10:54:28.196573 write(3, "\0\0\23\0\0\0\0\0\0\300\16\0\0\0\0\0\0 \26\0\0\0\0\0\0\320\17\0\0\0\0\0"..., 4096) = 4096 ...
由于順序讀,不需要反復(fù)定位文件偏移量,所以能夠?qū)W⒂趯懖僮?/p>
五、slat指標(biāo)
從上面的測(cè)試,我們?cè)趂io的測(cè)試報(bào)告中,并沒(méi)有發(fā)現(xiàn)slat的身影,那是由于上述都是同步操作,對(duì)同步 I/O 來(lái)說(shuō),由于 I/O 提交和 I/O 完成是一個(gè)動(dòng)作,所以 slat 實(shí)際上就是 I/O 完成的時(shí)間
異步順序?qū)懀瑢⑼巾樞驅(qū)懙拿钐砑?ioengine=libaio:
root@wilson-ubuntu:~# fio -name=write -rw=write -ioengine=libaio -direct=1 -bs=4k -size=1G -numjobs=1 -group_reporting -filename=/tmp/test.db write: (g=0): rw=write, bs=4K-4K/4K-4K/4K-4K, ioengine=libaio, iodepth=1 fio-2.2.10 Starting 1 process Jobs: 1 (f=1): [W(1)] [100.0% done] [0KB/119.3MB/0KB /s] [0/30.6K/0 iops] [eta 00m:00s] write: (groupid=0, jobs=1): err= 0: pid=27258: Wed Aug 14 11:14:36 2019 write: io=1024.0MB, bw=120443KB/s, iops=30110, runt= 8706msec slat (usec): min=3, max=70, avg= 4.31, stdev= 1.56 clat (usec): min=0, max=8967, avg=28.13, stdev=55.68 lat (usec): min=22, max=8976, avg=32.53, stdev=55.72 ... bw (KB /s): min=118480, max=122880, per=100.00%, avg=120467.29, stdev=1525.68 ... Run status group 0 (all jobs): WRITE: io=1024.0MB, aggrb=120442KB/s, minb=120442KB/s, maxb=120442KB/s, mint=8706msec, maxt=8706msec Disk stats (read/write): ... sda: ios=0/262147, merge=0/1, ticks=0/6576, in_queue=6568, util=74.32%
可以看到,slat指標(biāo)出現(xiàn),lat 近似等于 slat + clat 之和(avg平均值);并且換成異步io之后,吞吐量得到了極大的提升,120M左右
六、總結(jié)
● fio應(yīng)該作為磁盤的baseline工具,拿到機(jī)器(物理機(jī)或者云機(jī)器)都應(yīng)該第一時(shí)間對(duì)機(jī)器的磁盤做一個(gè)基線測(cè)試,做到心中有數(shù)
● 本文所有的測(cè)試,都是繞開了緩存,在實(shí)際應(yīng)用中需要將緩存的影響考慮進(jìn)去
以上所述是小編給大家介紹的linux磁盤順序?qū)?、隨機(jī)寫,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
標(biāo)簽:攀枝花 香港 淮北 西藏 怒江 西寧 濰坊 東營(yíng)
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《linux磁盤順序?qū)憽㈦S機(jī)寫的方法》,本文關(guān)鍵詞 linux,磁盤,順序,寫,隨機(jī),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。