14.6.3.4 Making the Buffer Pool Scan Resistant

Rather than using a strict LRU algorithm, InnoDB uses a technique to minimize the amount of data that is brought into the buffer pool and never accessed again. The goal is to make sure that frequently accessed (“hot”) pages remain in the buffer pool, even as read-ahead and full table scans bring in new blocks that might or might not be accessed afterward.
InnoDB并没有采用严格的LRU算法,而是使用一种技术来最小化输入到缓冲池中且不再访问的数据量。,目标是确保频繁访问(“热”)页面保留在缓冲池中,即使预读和全表扫描带来了之后可能会或可能不会访问的新块。
Newly read blocks are inserted into the middle of the LRU list. All newly read pages are inserted at a location that by default is 3/8 from the tail of the LRU list. The pages are moved to the front of the list (the most-recently used end) when they are accessed in the buffer pool for the first time. Thus, pages that are never accessed never make it to the front portion of the LRU list, and “age out” sooner than with a strict LRU approach. This arrangement divides the LRU list into two segments, where the pages downstream of the insertion point are considered “old” and are desirable victims for LRU eviction.
新读取的块被插入到LRU列表的中间,所有新读取的页面都插入到默认距离LRU列表尾部3/8的位置。第一次在缓冲池中访问页面时,页面将移动到列表的前面。 因此,永远不会被访问的页面永远不会将它放到LRU列表的前面,并且比使用严格的LRU方法更快地“老化”,这种安排将LRU列表划分为两个部分,其中插入点下游的页面被认为是“旧的”,是LRU收回的理想受害者。
For an explanation of the inner workings of the InnoDB buffer pool and specifics about the LRU algorithm, see Section 14.6.3.1, “The InnoDB Buffer Pool”.
有关InnoDB缓冲池内部工作原理和LRU算法细节的说明,请参见Section 14.6.3.1, “The InnoDB Buffer Pool”.
You can control the insertion point in the LRU list and choose whether InnoDB applies the same optimization to blocks brought into the buffer pool by table or index scans. The configuration parameter innodb_old_blocks_pct controls the percentage of “old” blocks in the LRU list. The default value of innodb_old_blocks_pct is 37, corresponding to the original fixed ratio of 3/8. The value range is 5 (new pages in the buffer pool age out very quickly) to 95 (only 5% of the buffer pool is reserved for hot pages, making the algorithm close to the familiar LRU strategy).
您可以控制LRU列表中的插入点,并选择InnoDB是否对通过表或索引扫描进入缓冲池的块应用相同的优化,配置参数innodb_old_blocks_pct控制LRU列表中“旧”块的百分比,innodb_old_blocks_pct的默认值是37,对应于3/8的原始固定比例,值的范围是5(缓冲池中的新页面非常快速地老化)到95(只有5%的缓冲池用于热页面,使得算法接近熟悉的LRU策略)。
The optimization that keeps the buffer pool from being churned by read-ahead can avoid similar problems due to table or index scans. In these scans, a data page is typically accessed a few times in quick succession and is never touched again. The configuration parameter innodb_old_blocks_time specifies the time window (in milliseconds) after the first access to a page during which it can be accessed without being moved to the front (most-recently used end) of the LRU list. The default value of innodb_old_blocks_time is 1000. Increasing this value makes more and more blocks likely to age out faster from the buffer pool.
保持缓冲池不被预读激活的优化可以避免由表或索引扫描造成的类似问题。在这些扫描中,一个数据页面通常会连续被访问几次,并且不会再被碰触。配置参数innodb_old_blocks_time指定了第一次访问页面之后的时间窗口(以毫秒为单位),在此期间可以访问该页面而不移动到LRU列表的前端,innodb_old_blocks_time的缺省值是1000.增加此值会使越来越多的块从缓冲池中快速老化。
Both innodb_old_blocks_pct and innodb_old_blocks_time are dynamic, global and can be specified in the MySQL option file (my.cnf or my.ini) or changed at runtime with the SET GLOBAL command. Changing the setting requires theSUPER privilege.
nnodb_old_blocks_pct和innodb_old_blocks_time都是动态的,全局的,可以在MySQL选项文件(my.cnf或my.ini)中指定,或者在运行时使用SET GLOBAL命令更改。 更改设置需要使用SUPER权限。
To help you gauge the effect of setting these parameters, the SHOW ENGINE INNODB STATUS command reports buffer pool statistics. For details, see Section 14.6.3.9, “Monitoring the Buffer Pool Using the InnoDB Standard Monitor”.
为了帮助您评估设置这些参数的效果,SHOW ENGINE INNODB STATUS命令可以报告缓冲池统计信息。 有关详细信息,请参见 Section 14.6.3.9, “Monitoring the Buffer Pool Using the InnoDB Standard Monitor”.
Because the effects of these parameters can vary widely based on your hardware configuration, your data, and the details of your workload, always benchmark to verify the effectiveness before changing these settings in any performance-critical or production environment.
由于这些参数的影响可能因您的硬件配置,数据和工作负载的详细信息而有很大差异,因此在任何性能关键或生产环境中更改这些设置之前,始终需要进行基准测试以验证其有效性。
In mixed workloads where most of the activity is OLTP type with periodic batch reporting queries which result in large scans, setting the value of innodb_old_blocks_time during the batch runs can help keep the working set of the normal workload in the buffer pool.
在混合工作负载中,大多数活动是OLTP类型,并且定期批量报告查询会导致大扫描,因此在批处理运行期间设置innodb_old_blocks_time的值可以帮助保持缓冲池中正常工作负载的工作集。
When scanning large tables that cannot fit entirely in the buffer pool, setting innodb_old_blocks_pct to a small value keeps the data that is only read once from consuming a significant portion of the buffer pool. For example, settinginnodb_old_blocks_pct=5 restricts this data that is only read once to 5% of the buffer pool.
扫描不能完全容纳在缓冲池中的大型表时,将innodb_old_blocks_pct设置为一个较小的值,可以使只读取一次的数据不会占用缓冲池的很大一部分。 例如,设置innodb_old_blocks_pct=5将只读取一次的数据限制为缓冲池的5%。
When scanning small tables that do fit into memory, there is less overhead for moving pages around within the buffer pool, so you can leave innodb_old_blocks_pct at its default value, or even higher, such as innodb_old_blocks_pct=50.
扫描适合内存的小表时,在缓冲池内移动页面所需的开销较小,因此您可以将innodb_old_blocks_pct保留为默认值,或者更高,例如innodb_old_blocks_pct = 50。
The effect of the innodb_old_blocks_time parameter is harder to predict than the innodb_old_blocks_pct parameter, is relatively small, and varies more with the workload. To arrive at an optimal value, conduct your own benchmarks if the performance improvement from adjusting innodb_old_blocks_pct is not sufficient.
innodb_old_blocks_time参数的影响比innodb_old_blocks_pct参数更难预测,相对较小,并且随工作负载而变化更大。要得到一个最佳值,如果调整innodb_old_blocks_pct的性能改进还不够的话,请进行您自己的基准测试。。

PREV: 14.6.3.3 Configuring Multiple Buffer Pool Instance https://blog.51cto.com/itzhoujun/2355878
NEXT: 14.6.3.5 Configuring InnoDB Buffer Pool Prefetchin https://blog.51cto.com/itzhoujun/2355880

上一篇:虚拟机添加硬盘RAID5并分区、格式化、挂载使用


下一篇:C语言学习笔记—code:blocks工具debug调试异常