標籤:檔案的 記錄檔 寫入 show nod aio -- 情境 mysq
一、mysql - innodb 使用非同步IO的情境
總的來說innodb 只會對資料檔案採用非同步IO,為了儲存日誌是真正被寫入到磁碟,innodb不會對記錄檔啟用非同步IO
更新細一步的說,innodb只會對資料檔案的read-ahead ,write 這兩個操作啟用非同步IO
二、非同步IO在mysql中解決了什麼問題:
在沒有IO這個功能之前,innodb對資料的讀寫請求先放入任務隊列,後台read-thread ,write-thread從任務隊列中
拿出任務並執行讀寫操作;後台讀寫線程的個數可以通過show engine innodb status 語句來查看
show engine innodb status;--------FILE I/O--------I/O thread 0 state: waiting for i/o request (insert buffer thread)I/O thread 1 state: waiting for i/o request (log thread)I/O thread 2 state: waiting for i/o request (read thread)I/O thread 3 state: waiting for i/o request (read thread)I/O thread 4 state: waiting for i/o request (read thread)I/O thread 5 state: waiting for i/o request (read thread)I/O thread 6 state: waiting for i/o request (write thread)I/O thread 7 state: waiting for i/o request (write thread)I/O thread 8 state: waiting for i/o request (write thread)I/O thread 9 state: waiting for i/o request (write thread)Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] , ibuf aio reads:, log i/o‘s:, sync i/o‘s:Pending flushes (fsync) log: 0; buffer pool: 0376 OS file reads, 54 OS file writes, 7 OS fsyncs41.77 reads/s, 21886 avg bytes/read, 6.00 writes/s, 0.78 fsyncs/s
由上面的內容可以看出預設情況下innodb會有4個read-thread 和4個write-thread ,問題就出現在這裡,如果業務繁重,那麼
讀寫任務就會非常的多,而innodb只有八個讀寫線程,這樣的話隊列中的其它讀寫請求就沒能得到及時的響應。
引入非同步IO之後就變天啦,讀寫請求不再像之前那樣先放入隊列,等著背景讀寫線程去執行任務;
----
mysql-5.7 Using Asynchronous I/O on Linux