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.
  • 在尾部,最近訪問較少的“舊”頁面的子列表。
    14.6.3.1 The InnoDB Buffer Pool

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.
  • 如果您的目的是通過填充表的內容來“預熱”緩衝池,則此策略不適用。例如,基準測試通常在服務器啓動時執行表或索引掃描,因爲這些數據通常會在正常使用一段時間後位於緩衝池中,在這種情況下,將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觸發的恢復緩衝池內容的過程。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章