MySQL :: MySQL 8.4 Reference Manual :: 17.8.3.4 Configuring InnoDB Buffer Pool Prefetching (Read-Ahead)
从官方文档目次“Configuring InnoDB Buffer Pool Prefetching”可以看出Prefetching是用来设置Innodb缓冲池的(O(∩_∩)O)。
重要是:Innodb_buffer_pool_read_ahead,Innodb_buffer_pool_read_ahead_evicted, Innodb_buffer_pool_read_ahead_rnd这三个参数,用来优化innodb 磁盘io。 设计目标:
Read-Ahead用于异步预取buffer pool中的多个page的一个猜测行为。
InnoDB使用两种提前预读Read-Ahead算法来进步I/O性能。 Linear read-ahead:线性预读
The SHOW ENGINE INNODB STATUS command displays statistics to help you evaluate the effectiveness of the read-ahead algorithm. Statistics include counter information for the following global status variables:
当从数据库请求数据时,首先搜索InnoDB缓冲池。如果数据未在缓冲池中找到,则必须将其从磁盘读入缓冲池。这也就是官网上说的Cound not satisfy from the buffer pool,缓冲池中无法中找到满足条件的数据,而必须从磁盘中读入缓冲池,这个操作称为Innodb_buffer_pool_reads(InnoDB缓冲池读取)。
aio 线程读取文件是受体系参数控制。特别是运行大量InnoDB I/O线程,比犹如一台服务器机器上运行多个如许的实例,可能会凌驾Linux体系的容量限制。
在这种情况下,可能会收到以下错误:
EAGAIN: The specified maxevents exceeds the user's limit of available events.
可以通过在/proc/sys/fs/aio-max-nr中写入更高的限制来解决这个错误。
在处理数据页时,假如需要对大量数据页举行筛选(但是没有用到),那么照旧会使大量的热点数据页被挤出。
如 select * from student where name like '张%';name字段包罗索引,那么在实验时虽然会先加载到老年代的头部,但是因为每条数据都需要筛选,所以都会移入新生代头部,导致新生代热点数据页被挤到老年代乃至移除。
InnoDB 为相识决这个问题,使用了 "老年代停留时间窗口" 机制,这个机制是设置一个时间,假如在老年代的数据页被调用后还需要去查抄它在老年代的停留时间是否达到了这个规定时间,达到了才能移入新生代头部,否则只会移到老年代头部。
at /newdata/mysql-8.0.23/storage/innobase/buf/buf0rea.cc:123
#11 0x0000000005367de7 in buf_read_page (page_id=..., page_size=...) at /newdata/mysql-8.0.23/storage/innobase/buf/buf0rea.cc:287
#12 0x000000000532ab34 in Buf_fetch<Buf_fetch_normal>::read_page (this=0x7fffc8563470) at /newdata/mysql-8.0.23/storage/innobase/buf/buf0buf.cc:3895
#13 0x000000000531b669 in Buf_fetch_normal::get (this=0x7fffc8563470, block=@0x7fffc8563418: 0x0) at /newdata/mysql-8.0.23/storage/innobase/buf/buf0buf.cc:3522
#14 0x000000000532b761 in Buf_fetch<Buf_fetch_normal>::single_page (this=0x7fffc8563470) at /newdata/mysql-8.0.23/storage/innobase/buf/buf0buf.cc:4089
mtr=0x7fffc8563ee0) at /newdata/mysql-8.0.23/storage/innobase/include/btr0btr.ic:76
#17 0x00000000052f0c1d in btr_pcur_t::move_to_next_page (this=0xb659c10, mtr=0x7fffc8563ee0) at /newdata/mysql-8.0.23/storage/innobase/btr/btr0pcur.cc:311
#18 0x0000000004fea918 in btr_pcur_t::move_to_next (this=0xb659c10, mtr=0x7fffc8563ee0) at /newdata/mysql-8.0.23/storage/innobase/include/btr0pcur.h:973
#19 0x00000000051a3a3c in row_search_mvcc (buf=0xb5c9468 "", mode=PAGE_CUR_G, prebuilt=0xb6599a0, match_mode=0, direction=1) at /newdata/mysql-8.0.23/storage/innobase/row/row0sel.cc:5912
#20 0x0000000004f26b95 in ha_innobase::general_fetch (this=0xb61b798, buf=0xb5c9468 "", direction=1, match_mode=0) at /newdata/mysql-8.0.23/storage/innobase/handler/ha_innodb.cc:10052
#21 0x0000000004f27661 in ha_innobase::rnd_next (this=0xb61b798, buf=0xb5c9468 "") at /newdata/mysql-8.0.23/storage/innobase/handler/ha_innodb.cc:10329
#22 0x0000000003b717dc in handler::ha_rnd_next (this=0xb61b798, buf=0xb5c9468 "") at /newdata/mysql-8.0.23/sql/handler.cc:2980
#23 0x00000000036eba58 in TableScanIterator::Read (this=0xb66f140) at /newdata/mysql-8.0.23/sql/records.cc:361
#24 0x0000000003ed6add in AggregateIterator::Read (this=0xb66f170) at /newdata/mysql-8.0.23/sql/composite_iterators.cc:295
#25 0x0000000003919704 in SELECT_LEX_UNIT::ExecuteIteratorQuery (this=0xb66be88, thd=0xaabeb10) at /newdata/mysql-8.0.23/sql/sql_union.cc:1228
#26 0x0000000003919a2e in SELECT_LEX_UNIT::execute (this=0xb66be88, thd=0xaabeb10) at /newdata/mysql-8.0.23/sql/sql_union.cc:1281
#27 0x0000000003871ef4 in Sql_cmd_dml::execute_inner (this=0xb66e288, thd=0xaabeb10) at /newdata/mysql-8.0.23/sql/sql_select.cc:827
#28 0x000000000387145a in Sql_cmd_dml::execute (this=0xb66e288, thd=0xaabeb10) at /newdata/mysql-8.0.23/sql/sql_select.cc:612
#29 0x00000000037fa060 in mysql_execute_command (thd=0xaabeb10, first_level=true) at /newdata/mysql-8.0.23/sql/sql_parse.cc:4407
#30 0x00000000037fbf41 in dispatch_sql_command (thd=0xaabeb10, parser_state=0x7fffc8566a50) at /newdata/mysql-8.0.23/sql/sql_parse.cc:4988
#31 0x00000000037f2543 in dispatch_command (thd=0xaabeb10, com_data=0x7fffc8567b00, command=COM_QUERY) at /newdata/mysql-8.0.23/sql/sql_parse.cc:1836
#32 0x00000000037f095e in do_command (thd=0xaabeb10) at /newdata/mysql-8.0.23/sql/sql_parse.cc:1320
#33 0x00000000039c5c91 in handle_connection (arg=0x9bd6950) at /newdata/mysql-8.0.23/sql/conn_handler/connection_handler_per_thread.cc:301
#34 0x000000000562cd84 in pfs_spawn_thread (arg=0xad3b3a0) at /newdata/mysql-8.0.23/storage/perfschema/pfs.cc:2900
#35 0x00007ffff7bc6ea5 in start_thread () from /lib64/libpthread.so.0
#36 0x00007ffff5e388dd in clone () from /lib64/libc.so.6
SHOW ENGINE INNODB STATUS还表现了预读页面的读取速率,以及这些页面在不被访问的情况下被驱逐的速率。每秒平均数据是基于上次调用SHOW ENGINE INNODB STATUS以来网络的统计数据,表现在SHOW ENGINE INNODB STATUS输出的BUFFER POOL and MEMORY部分。
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 137039872
Dictionary memory allocated 375221
Buffer pool size 8192
Free buffers 6850
Database pages 1338
Old database pages 513
。。。
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s