MySQL innodb I/O調優之日誌文件與日誌緩存

設置日誌文件大小
根據經驗,設置日誌總大小可以保持一個小時左右的服務器活動。
 
  1. mysql> show global status like 'Innodb_os_log_written';select sleep(60);show global status like 'Innodb_os_log_written'
  2. +-----------------------+-------+ 
  3. | Variable_name         | Value | 
  4. +-----------------------+-------+ 
  5. | Innodb_os_log_written | 3584  | 
  6. +-----------------------+-------+ 
  7. 1 row in set (0.00 sec) 
  8.  
  9. +-----------+ 
  10. | sleep(60) | 
  11. +-----------+ 
  12. |         0 | 
  13. +-----------+ 
  14. 1 row in set (1 min 0.04 sec) 
  15.  
  16. +-----------------------+--------+ 
  17. | Variable_name         | Value  | 
  18. +-----------------------+--------+ 
  19. | Innodb_os_log_written |  19200112 | 
  20. +-----------------------+--------+ 
  21. 1 row in set (0.00 sec) 
  22.  
  23. mysql>  select (19200112-3584)*60 /1024/1204 as MB_PER_HOUR; 
  24. +--------------+ 
  25. | MB_PER_HOUR  | 
  26. +--------------+ 
  27. | 934.21641404 | 
  28. +--------------+ 
  29. 1 row in set (0.00 sec) 

 

MySQL默認使用兩個日誌文件,設置innodb_log_file_size=500M

 

使用以下方式調整日誌文件大小:
 You usually don’t need to change the default number of logs, just the size of each log file. To change the log file size, shut
down MySQL cleanly, move the old logs away, reconfigure, and restart. Be sure MySQL
shuts down cleanly, or the log files will actually have entries that need to be applied to
the data files! Watch the MySQL error log when you restart the server. After you’ve
restarted successfully, you can delete the old log files.

 

 

設置日誌緩存大小
在innodb改變數據的時候,它會把這次改動的記錄寫到日誌緩衝裏面。日誌緩衝被保存在內存中。緩衝寫滿、事務提交或每一秒鐘,不管哪種情況先發生,Innodb都會把緩衝區寫到磁盤上的日誌文件中。如果有大型事務,可以增加innodb_log_buffer_size的大小(默認爲8M)來減少I/O動作。不需要把日誌緩衝區設置的很大,推薦的設置是1M到8M。除非寫入大量的巨型blob記錄或大事務,否則這個大小就足夠了。
  1. mysql> show global status like 'Innodb_log_waits'
  2. +------------------+-------+ 
  3. | Variable_name    | Value | 
  4. +------------------+-------+ 
  5. | Innodb_log_waits | 0     | 
  6. +------------------+-------+ 
  7. 1 row in set (0.00 sec) 

 

如果Innodb_log_waits狀態變量(等待日誌緩衝刷出的次數)的值比較高,而且繼續增長,可以增大log buffer或者降低事務大小。
 
innodb_log_file_size與innodb_log_buffer_size的設置需要重啓服務器。
 
參考:高性能MySQL (第二版)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章