14.6.3.1 The InnoDB Buffer Pool
作者:互联网
InnoDB maintains a storage area called the buffer pool for caching data and indexes in memory. Knowing how the InnoDB buffer pool works, and taking advantage of it to keep frequently accessed data in memory, is an important aspect of MySQL tuning. For information about how the InnoDB buffer pool works, see InnoDB Buffer Pool LRU Algorithm.
InnoDB维护一个称为缓冲池的存储区域,用于在内存中缓存数据和索引。了解InnoDB缓冲池如何工作,并利用它来将频繁访问的数据保存在内存中,这是MySQL调优的一个重要方面,有关InnoDB缓冲池如何工作的信息,请看 InnoDB Buffer Pool LRU Algorithm.
You can configure the various aspects of the InnoDB buffer pool to improve performance.
您可以配置InnoDB缓冲池的各个方面以提高性能。
- Ideally, you set the size of the buffer pool to as large a value as practical, leaving enough memory for other processes on the server to run without excessive paging. The larger the buffer pool, the more InnoDB acts like an in-memory database, reading data from disk once and then accessing the data from memory during subsequent reads. See Section 14.6.3.2, “Configuring InnoDB Buffer Pool Size”.
- 理想情况下,您可以将缓冲池的大小设置为实际的大小,从而为服务器上的其他进程留出足够的内存,而无需过多的分页。缓冲池越大,InnoDB就越像内存数据库,从磁盘读取数据一次,然后在后续读取期间从内存中访问数据,具体信息请看 Section 14.6.3.2, “Configuring InnoDB Buffer Pool Size”.
- With 64-bit systems with large memory sizes, you can split the buffer pool into multiple parts, to minimize contention for the memory structures among concurrent operations. For details, see Section 14.6.3.3, “Configuring Multiple Buffer Pool Instances”.
- 对于具有大内存的64位系统,可以将缓冲池分成多个部分,以最大限度地减少并发操作之间的内存结构争用,具体信息请看Section 14.6.3.3, “Configuring Multiple Buffer Pool Instances”.
- You can keep frequently accessed data in memory despite sudden spikes of activity for operations such as backups or reporting. For details, see Section 14.6.3.4, “Making the Buffer Pool Scan Resistant”.
- 尽管备份或报告等操作突然出现激增,您仍可以将经常访问的数据保留在内存中。具体信息请看Section 14.6.3.4, “Making the Buffer Pool Scan Resistant”.
- You can control when and how InnoDB performs read-ahead requests to prefetch pages into the buffer pool asynchronously, in anticipation that the pages will be needed soon. For details, see Section 14.6.3.5, “Configuring InnoDB Buffer Pool Prefetching (Read-Ahead)”.
- 您可以控制InnoDB何时以及如何执行预读请求,以便预先将页面异步预取到缓冲池中,因为预计这些页面将很快需要使用。具体信息请看Section 14.6.3.5, “Configuring InnoDB Buffer Pool Prefetching (Read-Ahead)”.
- You can control when background flushing of dirty pages occurs and whether or not InnoDB dynamically adjusts the rate of flushing based on workload. For details, see Section 14.6.3.6, “Configuring InnoDB Buffer Pool Flushing”.
- 您可以控制何时发生脏页面的后台刷新,以及InnoDB是否根据工作负载动态调整刷新率。详细信息请看 Section 14.6.3.6, “Configuring InnoDB Buffer Pool Flushing”.
- You can fine-tune aspects of InnoDB buffer pool flushing behavior to improve performance. For details, see Section 14.6.3.7, “Fine-tuning InnoDB Buffer Pool Flushing”.
- 您可以微调InnoDB缓冲池刷新行为的各个方面,以提高性能。具体信息请看Section 14.6.3.7, “Fine-tuning InnoDB Buffer Pool Flushing”.
- You can configure how InnoDB preserves the current buffer pool state to avoid a lengthy warmup period after a server restart. You can also save the current buffer pool state while the server is running. For details, see Section 14.6.3.8, “Saving and Restoring the Buffer Pool State”.
- 您可以配置InnoDB如何保留当前缓冲池状态,以避免服务器重新启动后的长时间预热。您也可以在服务器运行时保存当前的缓冲池状态,具体信息请看Section 14.6.3.8, “Saving and Restoring the Buffer Pool State”.
InnoDB Buffer Pool LRU Algorithm
InnoDB manages the buffer pool as a list, using a variation of the least recently used (LRU) algorithm. When room is needed to add a new page to the pool, InnoDB evicts the least recently used page and adds the new page to the middle of the list. This “midpoint insertion strategy” treats the list as two sublists:
InnoDB使用最近最少使用(LRU)算法的变体,将缓冲池作为列表来管理。当需要空间将新页面添加到池中时,InnoDB会驱逐最近最少使用的页面,并将新页面添加到列表的中间,这种“中点插入策略”将列表视为两个子列表:
- At the head, a sublist of “new” (or “young”) pages that were accessed recently.
- 在头部,最近访问过的“新”(或“年轻”)页面的子列表。
- At the tail, a sublist of “old” pages that were accessed less recently.
- 在尾部,最近访问较少的“旧”页面的子列表。
This algorithm keeps pages that are heavily used by queries in the new sublist. The old sublist contains less-used pages; these pages are candidates for eviction.
此算法将查询大量使用的页面保留在新子列表中。 旧子列表包含较少使用的页面; 这些页面是被驱逐的候选页面。
The LRU algorithm operates as follows by default:
LRU算法默认运行如下:
- 3/8 of the buffer pool is devoted to the old sublist.
- 3/8的缓冲池专用于旧的子列表。
- The midpoint of the list is the boundary where the tail of the new sublist meets the head of the old sublist.
- 列表的中点是新子列表尾部与旧子列表头部相交的边界。
- When InnoDB reads a page into the buffer pool, it initially inserts it at the midpoint (the head of the old sublist). A page can be read in because it is required for a user-specified operation such as an SQL query, or as part of a read-aheadoperation performed automatically by InnoDB.
- 当InnoDB将一个页面读入缓冲池时,它最初将它插入到中点(旧子列表的头部),页面可以被读入,因为它是用户指定的操作(如SQL查询)所必需的,或者作为InnoDB自动执行的预读操作的一部分。
- Accessing a page in the old sublist makes it “young”, moving it to the head of the buffer pool (the head of the new sublist). If the page was read in because it was required, the first access occurs immediately and the page is made young. If the page was read in due to read-ahead, the first access does not occur immediately (and might not occur at all before the page is evicted).
- 在旧的子列表中访问一个页面会使其变得“年轻”,并将其移动到缓冲池的头部(新子列表的头部)。 如果页面因为需要而被读入,则第一次访问立即发生并且页面变得年轻。如果由于预读而导致页面被读入,则第一次访问不会立即发生(并且在页面被逐出之前可能根本不会发生)。
- As the database operates, pages in the buffer pool that are not accessed “age” by moving toward the tail of the list. Pages in both the new and old sublists age as other pages are made new. Pages in the old sublist also age as pages are inserted at the midpoint. Eventually, a page that remains unused for long enough reaches the tail of the old sublist and is evicted.
- 当数据库运行时,缓冲池中未被访问的页通过向列表尾部移动而“老化”。新的和旧的子列表中的页面都随着其他页面的更新而变老。旧子列表中的页面也会随着页面在中点插入而老化。最终,一个长时间未使用的页面到达旧子列表的尾部并被逐出。
By default, pages read by queries immediately move into the new sublist, meaning they stay in the buffer pool longer. A table scan (such as performed for a mysqldump operation, or a SELECT statement with no WHERE clause) can bring a large amount of data into the buffer pool and evict an equivalent amount of older data, even if the new data is never used again. Similarly, pages that are loaded by the read-ahead background thread and then accessed only once move to the head of the new list. These situations can push frequently used pages to the old sublist, where they become subject to eviction. For information about optimizing this behavior, see Section 14.6.3.4, “Making the Buffer Pool Scan Resistant”, and Section 14.6.3.5, “Configuring InnoDB Buffer Pool Prefetching (Read-Ahead)”.
默认情况下,查询读取的页面会立即移动到新的子列表中,这意味着它们会留在缓冲池中的时间更长。表扫描(例如执行mysqldump操作,或者不带WHERE子句的SELECT语句)可以将大量数据带入缓冲池并驱逐等量的旧数据,即使新数据再也不会使用。类似地,由预读后台线程加载然后仅访问一次的页面移动到新列表的头部。 这些情况可以将经常使用的页面推送到旧的子列表,在那里它们会被驱逐,有关优化此行为的信息请看 Section 14.6.3.4, “Making the Buffer Pool Scan Resistant”,和 Section 14.6.3.5, “Configuring InnoDB Buffer Pool Prefetching (Read-Ahead)”.
InnoDB Standard Monitor output contains several fields in the BUFFER POOL AND MEMORY section that pertain to operation of the buffer pool LRU algorithm. For details, see Section 14.6.3.9, “Monitoring the Buffer Pool Using the InnoDB Standard Monitor”.
InnoDB标准监视器输出包含BUFFER POOL AND MEMORY 节中关于缓冲池LRU算法操作的几个字段。更多信息请看 Section 14.6.3.9, “Monitoring the Buffer Pool Using the InnoDB Standard Monitor”.
InnoDB Buffer Pool Configuration Options
InnoDB缓冲池配置选项
Several configuration options affect different aspects of the InnoDB buffer pool.
几个配置选项影响InnoDB缓冲池的不同方面。
- innodb_buffer_pool_size
Specifies the size of the buffer pool. If the buffer pool is small and you have sufficient memory, making the buffer pool larger can improve performance by reducing the amount of disk I/O needed as queries access InnoDB tables. The innodb_buffer_pool_size option is dynamic, which allows you to configure buffer pool size without restarting the server. See Section 14.6.3.2, “Configuring InnoDB Buffer Pool Size” for more information. - 指定缓冲池的大小。 如果缓冲池很小并且有足够的内存,使缓冲池更大可以通过减少查询访问InnoDB表所需的磁盘I/O数量来提高性能。innodb_buffer_pool_size选项是动态的,它允许您在不重新启动服务器的情况下配置缓冲池大小。 有关更多信息,请参见 Section 14.6.3.2, “Configuring InnoDB Buffer Pool Size”
- innodb_buffer_pool_chunk_size
Defines the chunk size for InnoDB buffer pool resizing operations. See Section 14.6.3.2, “Configuring InnoDB Buffer Pool Size” for more information. - 定义InnoDB缓冲池调整操作的块大小。。 有关更多信息,请参见Section 14.6.3.2, “Configuring InnoDB Buffer Pool Size”
- innodb_buffer_pool_instances
Divides the buffer pool into a user-specified number of separate regions, each with its own LRU list and related data structures, to reduce contention during concurrent memory read and write operations. This option only takes effect when you set innodb_buffer_pool_size to a value of 1GB or more. The total size you specify is divided among all the buffer pools. For best efficiency, specify a combination of innodb_buffer_pool_instances andinnodb_buffer_pool_size so that each buffer pool instance is at least 1 gigabyte. See Section 14.6.3.3, “Configuring Multiple Buffer Pool Instances” for more information. - 将缓冲池划分为用户指定数量的单独区域,每个区域都有自己的LRU列表和相关数据结构,以减少并发内存读写操作期间的争用。当您将innodb_buffer_pool_size设置为1GB或更大的值时,此选项才会生效。 此选项仅在将innodb_buffer_pool_size设置为1GB或更大的值时生效。 您指定的总大小在所有缓冲池之间分配。为了获得最佳效率,请指定innodb_buffer_pool_instances和innodb_buffer_pool_size 的组合,以便每个缓冲池实例至少有1千兆字节,更多信息请看Section 14.6.3.3, “Configuring Multiple Buffer Pool Instances”
- innodb_old_blocks_pct
Specifies the approximate percentage of the buffer pool that InnoDB uses for the old block sublist. The range of values is 5 to 95. The default value is 37 (that is, 3/8 of the pool). See Section 14.6.3.4, “Making the Buffer Pool Scan Resistant”for more information. - 指定InnoDB用于旧块子列表的缓冲池的近似百分比。 值的范围是5到95.默认值是37(即池的3/8)。更多信息请看 Section 14.6.3.4, “Making the Buffer Pool Scan Resistant”
- innodb_old_blocks_time
Specifies how long in milliseconds (ms) a page inserted into the old sublist must stay there after its first access before it can be moved to the new sublist. If the value is 0, a page inserted into the old sublist moves immediately to the new sublist the first time it is accessed, no matter how soon after insertion the access occurs. If the value is greater than 0, pages remain in the old sublist until an access occurs at least that many milliseconds after the first access. For example, a value of 1000 causes pages to stay in the old sublist for 1 second after the first access before they become eligible to move to the new sublist.
Setting innodb_old_blocks_time greater than 0 prevents one-time table scans from flooding the new sublist with pages used only for the scan. Rows in a page read in for a scan are accessed many times in rapid succession, but the page is unused after that. If innodb_old_blocks_time is set to a value greater than time to process the page, the page remains in the “old” sublist and ages to the tail of the list to be evicted quickly. This way, pages used only for a one-time scan do not act to the detriment of heavily used pages in the new sublist.
innodb_old_blocks_time can be set at runtime, so you can change it temporarily while performing operations such as table scans and dumps: -
指定插入到旧子列表中的页面在第一次访问后必须保留在那里的毫秒(ms)时间,然后才能移动到新的子列表,如果值为0,则插入到旧子列表中的页面会在第一次访问时立即移动到新子列表中,无论插入后多久发生访问。如果该值大于0,则页面保留在旧的子列表中,直到在第一次访问之后至少几毫秒发生访问,例如,值为1000会导致页面在第一次访问后停留在旧子表中1秒钟,然后才有资格移动到新子列表。设置innodb_old_blocks_time大于0可以防止一次性的表扫描将只用于扫描的页面填充到新子列表中。.读取的扫描页面中的行会连续快速访问多次,但该页面在此之后未被使用。 如果innodb_old_blocks_time设置为大于处理页面的时间的值,则该页面保留在“旧”子列表中,并且老化到列表的尾部以被快速驱逐。 这样,仅用于一次扫描的页面不会影响新子列表中大量使用的页面。innodb_old_blocks_time可以在运行时设置,因此您可以在执行诸如表扫描和转储等操作时临时更改它:
SET GLOBAL innodb_old_blocks_time = 1000;
... perform queries that scan tables ...
SET GLOBAL innodb_old_blocks_time = 0;- This strategy does not apply if your intent is to “warm up” the buffer pool by filling it with a table's content. For example, benchmark tests often perform a table or index scan at server startup, because that data would normally be in the buffer pool after a period of normal use. In this case, leave innodb_old_blocks_time set to 0, at least until the warmup phase is complete.
See Section 14.6.3.4, “Making the Buffer Pool Scan Resistant” for more information.
- This strategy does not apply if your intent is to “warm up” the buffer pool by filling it with a table's content. For example, benchmark tests often perform a table or index scan at server startup, because that data would normally be in the buffer pool after a period of normal use. In this case, leave innodb_old_blocks_time set to 0, at least until the warmup phase is complete.
- 如果您的目的是通过填充表的内容来“预热”缓冲池,则此策略不适用。例如,基准测试通常在服务器启动时执行表或索引扫描,因为这些数据通常会在正常使用一段时间后位于缓冲池中,在这种情况下,将innodb_old_blocks_time设置为0,至少在热身阶段完成之前是这样。更多信息请看Section 14.6.3.4, “Making the Buffer Pool Scan Resistant”
- innodb_read_ahead_threshold
Controls the sensitivity of linear read-ahead that InnoDB uses to prefetch pages into the buffer pool.
See Section 14.6.3.5, “Configuring InnoDB Buffer Pool Prefetching (Read-Ahead)” for more information. - 控制InnoDB用于预取页面到缓冲池中的线性预读的灵敏度。更多信息请看Section 14.6.3.5, “Configuring InnoDB Buffer Pool Prefetching (Read-Ahead)”
- innodb_random_read_ahead
Enables random read-ahead technique for prefetching pages into the buffer pool. Random read-ahead is a technique that predicts when pages might be needed soon based on pages already in the buffer pool, regardless of the order in which those pages were read. innodb_random_read_ahead is disabled by default.
See Section 14.6.3.5, “Configuring InnoDB Buffer Pool Prefetching (Read-Ahead)” for more information. - 使用随机预读技术将页面预取到缓冲池中。随机预读是一项技术,可根据缓冲池中已有的页面快速预测何时可能需要页面,而不管这些页面的读取顺序如何。innodb_random_read_ahead 默认是禁用的,更多信息请看Section 14.6.3.5, “Configuring InnoDB Buffer Pool Prefetching (Read-Ahead)”
- innodb_adaptive_flushing
Specifies whether to dynamically adjust the rate of flushing dirty pages in the buffer pool based on workload. Adjusting the flush rate dynamically is intended to avoid bursts of I/O activity. This setting is enabled by default.
See Section 14.6.3.6, “Configuring InnoDB Buffer Pool Flushing” for more information.
指定是否根据工作负载动态调整缓冲池中刷新dirty pages 速率。 动态调整冲刷速率旨在避免I/O活动的爆发。 该设置默认启用。更多信息请看Section 14.6.3.6, “Configuring InnoDB Buffer Pool Flushing” - innodb_adaptive_flushing_lwm
Low water mark representing percentage of redo log capacity at which adaptive flushing is enabled.
See Section 14.6.3.7, “Fine-tuning InnoDB Buffer Pool Flushing” for more information. - 低水位标记表示启用adaptive flushing 的重做日志容量的百分比。。
- innodb_flush_neighbors
Specifies whether flushing a page from the buffer pool also flushes other dirty pages in the same extent.
See Section 14.6.3.7, “Fine-tuning InnoDB Buffer Pool Flushing” for more information. - 指定从缓冲池 flushing页面是否也刷新相同 extent内的其他dirty pages 。
- innodb_flushing_avg_loops
Number of iterations for which InnoDB keeps the previously calculated snapshot of the flushing state, controlling how quickly adaptive flushing responds to changing workloads.
See Section 14.6.3.7, “Fine-tuning InnoDB Buffer Pool Flushing” for more information. - InnoDB保存之前计算的刷新状态快照的迭代次数,控制自适应刷新对更改工作负载的响应速度。
- innodb_lru_scan_depth
A parameter that influences the algorithms and heuristics for the flush operation for the buffer pool. Primarily of interest to performance experts tuning I/O-intensive workloads. It specifies, per buffer pool instance, how far down the buffer pool LRU list the page_cleaner thread scans looking for dirty pages to flush. - 影响缓冲池刷新操作的算法和启发式的参数。 性能专家主要关注调整I / O密集型工作负载。它指定每个缓冲池实例在缓冲池LRU中列出page_cleaner线程扫描的范围,以查找要刷新的脏页。
See Section 14.6.3.7, “Fine-tuning InnoDB Buffer Pool Flushing” for more information. - innodb_max_dirty_pages_pct
InnoDB tries to flush data from the buffer pool so that the percentage of dirty pages does not exceed this value. Specify an integer in the range from 0 to 99. The default value is 75.
See Section 14.6.3.6, “Configuring InnoDB Buffer Pool Flushing” for more information. - InnoDB会尝试从缓冲池中刷新数据,以便脏页面的百分比不超过此值。 指定范围从0到99的整数。默认值为75。
- innodb_max_dirty_pages_pct_lwm
Low water mark representing percentage of dirty pages where preflushing is enabled to control the dirty page ratio. The default of 0 disables the pre-flushing behavior entirely.See Section 14.6.3.7, “Fine-tuning InnoDB Buffer Pool Flushing” for more information. - 低水印表示启用预冲以控制脏页比率的dirty pages的百分比。 默认值为0将完全禁用预冲洗行为。
- innodb_buffer_pool_filename
- Specifies the name of the file that holds the list of tablespace IDs and page IDs produced byinnodb_buffer_pool_dump_at_shutdown or innodb_buffer_pool_dump_now.
See Section 14.6.3.8, “Saving and Restoring the Buffer Pool State” for more information. - 指定保存由innodb_buffer_pool_dump_at_shutdown或innodb_buffer_pool_dump_now生成的表空间ID和页面ID列表的文件的名称
- innodb_buffer_pool_dump_at_shutdown
Specifies whether to record the pages cached in the buffer pool when the MySQL server is shut down, to shorten thewarmup process at the next restart.
See Section 14.6.3.8, “Saving and Restoring the Buffer Pool State” for more information. - 指定在MySQL服务器关闭时是否记录缓冲池中缓存的页面,以便在下次重新启动时缩短预热过程。
- innodb_buffer_pool_load_at_startup
Specifies that, on MySQL server startup, the buffer pool is automatically warmed up by loading the same pages it held at an earlier time. Typically used in combination with innodb_buffer_pool_dump_at_shutdown.
See Section 14.6.3.8, “Saving and Restoring the Buffer Pool State” for more information. - 指定在MySQL服务器启动时,通过加载以前保存的相同页面自动预热缓冲池。 通常与innodb_buffer_pool_dump_at_shutdown结合使用。
- innodb_buffer_pool_dump_now
Immediately records the pages cached in the buffer pool.
See Section 14.6.3.8, “Saving and Restoring the Buffer Pool State” for more information. - 立即记录在缓冲池中缓存的页面。
- innodb_buffer_pool_load_now
Immediately warms up the buffer pool by loading a set of data pages, without waiting for a server restart. Can be useful to bring cache memory back to a known state during benchmarking, or to ready the MySQL server to resume its normal workload after running queries for reports or maintenance. Typically used withinnodb_buffer_pool_dump_now. - 立即通过加载一组数据页面来预热缓冲池,而无需等待服务器重新启动。 在基准测试期间将高速缓存恢复到已知状态,或者在运行查询报告或维护后,使MySQL服务器恢复正常工作负载,可能会很有用。 通常在nodb_buffer_pool_dump_now中使用。
See Section 14.6.3.8, “Saving and Restoring the Buffer Pool State” for more information. - innodb_buffer_pool_dump_pct
Specifies the percentage of the most recently used pages for each buffer pool to read out and dump. The range is 1 to 100.
See Section 14.6.3.8, “Saving and Restoring the Buffer Pool State” for more information. - 指定每个缓冲池读出和转储的最近使用页面的百分比。 范围是1到100。
- innodb_buffer_pool_load_abort
Interrupts the process of restoring buffer pool contents triggered by innodb_buffer_pool_load_at_startup or innodb_buffer_pool_load_now.
See Section 14.6.3.8, “Saving and Restoring the Buffer Pool State” for more information. - 中断由innodb_buffer_pool_load_at_startup或innodb_buffer_pool_load_now触发的恢复缓冲池内容的过程。
标签:14.6,Buffer,buffer,InnoDB,pool,innodb,Pool 来源: https://blog.51cto.com/itzhoujun/2355337