204_mysql_innodb_5_innodb 后臺線程
Innodb引擎是多線程模型,不同后臺線程, 負責處理不同業務

# 1. 前臺線程(連接層)
show processlist ; show full processlist; select * from information_schema.processlist ;
# 2. 后臺線程(Server\Engine)
mysql> select * from performance_schema.threads\G 說明: 如何查詢到連接線程和SQL線程關系 select * from information_schema.processlist ; ---> ID=10 select * from performance_schema.threads where processlist_id=10\G
1 master thread核心線程
負責
控制刷新臟頁到磁盤(CKPT)
控制日志緩沖刷新到磁盤(log buffer ---> redo)
undo頁回收
合并插入緩沖(change buffer)
控制IO刷新數量
說明: innodb_io_capacity表示每秒刷新臟頁的數量,默認為200。 innodb_max_dirty_pages_pct設置出發刷盤的臟頁百分比,即當臟頁占到緩沖區數據達到這個百分比時,就會刷新innodb_io_capacity個臟頁到磁盤。 innodb_adaptive_flushing = ON(自適應地刷新),該值影響每秒刷新臟頁的數量。 原來的刷新規則是:臟頁在緩沖池所占的比例小于 innodb_max_dirty_pages_pct時,不刷新臟頁;大于innodb_max_dirty_pages_pct時,刷新100個臟頁。 隨著innodb_adaptive_flushing參數的引入,InnoDB存儲引擎會通過一個名為buf_flush_get_desired_flush_rate的函數來判斷需要刷新臟頁最合適的數量。 buf_flush_get_desired_flush_rate通過判斷產生重做日志(redolog)的速度來決定最合適的刷新臟頁數量 因此,當臟頁的比例小于innodb_max_dirty_pages_pct時,也會刷新一定量的臟頁。
2 IO thread
Innodb 使用 AIO(Async IO)來處理寫IO請求,提高性能, 4個核心IO thread? read/write? insert buffer/log io thread
show variables like '%innodb_%io_threads';
show engine innodb status \G;
I/O thread 0 state: wait Windows aio (insert buffer thread) I/O thread 1 state: wait Windows aio (log thread) I/O thread 2 state: wait Windows aio (read thread) I/O thread 3 state: wait Windows aio (read thread) I/O thread 4 state: wait Windows aio (read thread) I/O thread 5 state: wait Windows aio (read thread) I/O thread 6 state: wait Windows aio (write thread) I/O thread 7 state: wait Windows aio (write thread) I/O thread 8 state: wait Windows aio (write thread) I/O thread 9 state: wait Windows aio (write thread)
3 Purge Thread
事物提交后 需要purge? thread 來回收已經使用分配的undo頁
show variables like '%innodb_purge_threads%';
4 page cleaner Thread
將刷臟頁單獨線程完成,較少 master thread 壓力,提高性能
show variables like '%innodb_page_cleaners%';
5 其它線程: SQL線程/連接層的線程(前臺)
其它
查詢系統中所有業務表的存儲引擎信息
查詢系統中所有業務表的存儲引擎信息 select table_schema, table_name , engine from information_schema.tables where table_schema not in ('sys','mysql','information_schema','performance_schema'); 巡檢需求: 將業務表中所有非InnoDB查詢出來 mysql> select table_schema,table_name,engine from information_schema.tables where table_schema not in ('mysql','sys','information_schema','performance_schema') and engine !='innodb'; 1. 查詢所有非InnoDB表 mysql> select table_schema,table_name ,engine from information_schema.tables where table_schema not in ('sys','mysql','information_schema','performance_schema') and engine !='innodb'; 2. 備份所有非InnoDB表 select concat("mysqldump -uroot -p123 ",table_schema," ",table_name," >/tmp/",table_schema,"_",table_name,".sql") from information_schema.tables where table_schema not in ('sys','mysql','information_schema','performance_schema') and engine !='innodb'; 3. 修改存儲引擎 mysql> select concat("alter table ",table_schema,".",table_name," engine=innodb;") from information_schema.tables where table_schema not in ('sys','mysql','information_schema','performance_schema') and engine !='innodb' into outfile '/tmp/a.sql'; mysql> source /tmp/a.sql 3. 修改存儲引擎 mysql> select concat("alter table ",table_schema,".",table_name," engine=innodb;") from information_schema.tables where table_schema not in ('sys','mysql','information_schema','performance_schema') and engine !='innodb' into outfile '/tmp/a.sql'; mysql> source /tmp/a.sql
碎片情況
alter table world.xxx engine=innodb ALGORITHM=COPY; analyze table world.city; 轉儲表(推薦) create table t1_bak like t1; insert into t1_bak selewct * from t1; drop table t1 ; rename table t1_bak to t1; Mysqldump 導出 導入。 或者工具 pt-os ghost 注意: 1. 最好是空窗期做 2. 準備double的存儲空間 tmpdir 3. 整理碎片只對 InnoDB 獨立表空間方式有效
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。