一、數據庫是一個寫頻繁的系統
二、後臺寫、寫緩存
三、commit須要寫入
四、寫緩存失效或者寫滿-->寫壓力陡增-->寫佔讀的帶寬
一、BBU失效
二、寫入忽然增長、cache滿
五、日誌寫入、髒緩衝區寫入mysql
[root@localhost mydata]# iostat -x Linux 2.6.32-642.el6.x86_64 (localhost.chinaitsoft.com) 07/05/2017 _x86_64_ (8 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 0.00 0.00 0.03 0.00 0.00 99.97 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await r_await w_await svctm %util scd0 0.00 0.00 0.00 0.00 0.01 0.00 7.72 0.00 1.25 1.25 0.00 1.25 0.00 sdc 0.02 0.00 0.01 0.00 0.07 0.00 7.93 0.00 0.89 0.89 0.00 0.72 0.00 sda 0.18 0.13 0.13 0.05 5.38 1.43 37.95 0.00 6.63 3.99 13.77 2.23 0.04 sdb 0.03 0.00 0.01 0.00 0.12 0.00 8.72 0.00 1.14 0.80 35.89 0.71 0.00
mysql> show global status like '%pend%'; +------------------------------+-------+ | Variable_name | Value | +------------------------------+-------+ | Innodb_data_pending_fsyncs | 0 | #被掛起的fsync | Innodb_data_pending_reads | 0 | #被掛起的物理讀 | Innodb_data_pending_writes | 0 | #被掛起的寫 | Innodb_os_log_pending_fsyncs | 0 | #被掛起的日誌fsync | Innodb_os_log_pending_writes | 0 | #被掛起的日誌寫 +------------------------------+-------+ 5 rows in set (0.01 sec)
mysql> show global status like '%log%written'; +-----------------------+-------+ | Variable_name | Value | +-----------------------+-------+ | Innodb_os_log_written | 5120 | +-----------------------+-------+ 1 row in set (0.01 sec)
mysql> show global status like '%a%written'; +----------------------------+---------+ | Variable_name | Value | +----------------------------+---------+ | Innodb_data_written | 1073152 | #目前爲止寫的總的數據量,單位字節 | Innodb_dblwr_pages_written | 7 | | Innodb_pages_written | 58 | #寫數據頁的數量 +----------------------------+---------+ 3 rows in set (0.01 sec)
mysql> show global status like '%dblwr%'; +----------------------------+-------+ | Variable_name | Value | +----------------------------+-------+ | Innodb_dblwr_pages_written | 7 | #已經寫入到doublewrite buffer的頁的數量 | Innodb_dblwr_writes | 3 | #doublewrite寫的次數 +----------------------------+-------+ 2 rows in set (0.00 sec)
mysql> show global status like '%dirty%'; +--------------------------------+-------+ | Variable_name | Value | +--------------------------------+-------+ | Innodb_buffer_pool_pages_dirty | 0 | #當前buffer pool中髒頁的數量 | Innodb_buffer_pool_bytes_dirty | 0 | #當前buffer pool中髒頁的總字節數 +--------------------------------+-------+ 2 rows in set (0.01 sec) mysql> show global status like 'i%total%'; +--------------------------------+-------+ | Variable_name | Value | +--------------------------------+-------+ | Innodb_buffer_pool_pages_total | 8192 | #buffer pool中數據頁總量 +--------------------------------+-------+ 1 row in set (0.01 sec)
mysql> show global status like '%t_free'; +------------------------------+-------+ | Variable_name | Value | +------------------------------+-------+ | Innodb_buffer_pool_wait_free | 0 | +------------------------------+-------+ 1 row in set (0.01 sec) mysql> show global status like '%g_waits'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | Innodb_log_waits | 0 | +------------------+-------+ 1 row in set (0.00 sec)
mysql> show global status like 'i%rows%'; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | Innodb_rows_deleted | 0 | | Innodb_rows_inserted | 145 | | Innodb_rows_read | 233 | | Innodb_rows_updated | 5 | +----------------------+-------+ 4 rows in set (0.01 sec) mysql> show global status like '%commit%'; +----------------+-------+ | Variable_name | Value | +----------------+-------+ | Com_commit | 0 | | Com_xa_commit | 0 | | Handler_commit | 16 | +----------------+-------+ 3 rows in set (0.01 sec) mysql> show global status like '%rollback%'; +----------------------------+-------+ | Variable_name | Value | +----------------------------+-------+ | Com_rollback | 0 | | Com_rollback_to_savepoint | 0 | | Com_xa_rollback | 0 | | Handler_rollback | 0 | | Handler_savepoint_rollback | 0 | +----------------------------+-------+ 5 rows in set (0.01 sec)
mysql> show variables like 'i%depth%'; +-----------------------+-------+ | Variable_name | Value | +-----------------------+-------+ | innodb_lru_scan_depth | 1024 | +-----------------------+-------+ 1 row in set (0.01 sec)
mysql> show variables like '%io_c%'; +------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | innodb_io_capacity | 200 | | innodb_io_capacity_max | 2000 | +------------------------+-------+ 2 rows in set (0.00 sec)
mysql> show variables like 'innodb_log%'; +-----------------------------+----------+ | Variable_name | Value | +-----------------------------+----------+ | innodb_log_buffer_size | 16777216 | | innodb_log_checksums | ON | #解決數據在io環節的出錯問題,checksum值檢查 | innodb_log_compressed_pages | ON | | innodb_log_file_size | 50331648 | | innodb_log_files_in_group | 2 | | innodb_log_group_home_dir | ./ | | innodb_log_write_ahead_size | 8192 | +-----------------------------+----------+ 7 rows in set (0.01 sec)
mysql> show variables like '%flush%commit'; +--------------------------------+-------+ | Variable_name | Value | +--------------------------------+-------+ | innodb_flush_log_at_trx_commit | 1 | +--------------------------------+-------+ 1 row in set (0.00 sec)
關於redolog的刷盤策略:也就是用戶在commit,事務提交時,處理redolog的方式(0、一、2):0:當提交事務時,並不將事務的redo log寫入logfile中,而是等待master thread每秒的刷新redo log。(數據庫崩潰丟失數據,丟一秒鐘的事務)
1:執行commit時將redo log同步寫到磁盤logfile中,即伴有fsync的調用(默認是1,保證不丟失事務)
2:在每一個提交,日誌緩衝被寫到文件系統緩存,但不是寫到磁盤的刷新(數據庫宕機而操做系統及服務器並無宕機,當恢復時能保證數據不丟失;可是文件系統(OS)崩潰會丟失數據)
mysql> show variables like 'innodb_flush_log_at_timeout'; +-----------------------------+-------+ | Variable_name | Value | +-----------------------------+-------+ | innodb_flush_log_at_timeout | 1 | +-----------------------------+-------+ 1 row in set (0.01 sec)
mysql> show variables like '%dirty%pct%'; +--------------------------------+-----------+ | Variable_name | Value | +--------------------------------+-----------+ | innodb_max_dirty_pages_pct | 75.000000 | #髒頁在buffer pool中的最大佔比 | innodb_max_dirty_pages_pct_lwm | 0.000000 | +--------------------------------+-----------+ 2 rows in set (0.01 sec)
在內存buffer pool空間容許的範圍下,能夠調大髒頁容許在內存空間的佔比,可解燃眉之急,下降寫壓力。ios
mysql> show variables like '%doub%'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | innodb_doublewrite | ON | +--------------------+-------+ 1 row in set (0.01 sec)