赞
踩
多线程模型
后台线程功能
后台线程种类
在InnoDB中,大量采用了异步IO(AIO)技术来进行读写处理,这一特性可以显著提高数据库的性能。通过异步IO,InnoDB能够在进行IO操作时不阻塞其他线程的执行,从而更高效地处理读写请求。
IO线程配置
在InnoDB 1.0版本之前,共有4个IO Thread,分别是:
而在后续版本中,read thread和write thread分别增大到了4个,总共有10个IO线程。
要查看InnoDB的IO线程状态,可以使用MySQL的命令show engine innodb status;
,该命令将显示当前InnoDB引擎的详细状态信息,包括IO线程的数量和状态等。
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: 0 681521 OS file reads, 1808551 OS file writes, 1586763 OS fsyncs 0.00 reads/s, 0 avg bytes/read, 0.12 writes/s, 0.12 fsyncs/s
Thread事务提交之后,其使用的undo日志将不再需要,因此需要Purge Thread回收已经分配的undo页。
mysql> show variables like '%innodb_purge_threads%';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| innodb_purge_threads | 4 |
+----------------------+-------+
1 row in set (0.01 sec)
InnoDB1.2+开始,支持多个Purge Thread 这样做的目的为了加快回收undo页(释放内存)
作用是将脏数据刷新到磁盘,脏数据刷盘后相应的redo log也就可以覆盖,即可以同步数据,又能达到redo log循环使用的目的。会调用write thread线程处理。
mysql> show variables like '%innodb_page_cleaners%';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| innodb_page_cleaners | 1 |
+----------------------+-------+
InnoDB的Master Thread是主线程,担负着调度其他各个线程的重要任务,其优先级最高。主要功能包括:
示例输出:
mysql> show variables like 'innodb_io_capacity';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| innodb_io_capacity | 200 |
+--------------------+-------+
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。